Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Good morning, I solved the beginning of the following Java code. When I enter a

ID: 3698450 • Letter: G

Question

Good morning, I solved the beginning of the following Java code. When I enter a float, it does not run. The sample output is below, thank you.

import java.util.Scanner;

class Main {
public static void main(String[] args) {
  
//using scanner for getting input from user
  
Scanner in = new Scanner(System.in);
  
String s = in.nextLine();
System.out.println("You entered string: "+s);
  
int a = in.nextInt();
System.out.println("You entered string: "+a);
float b = in.nextFloat();
System.out.println("You entered float: "+b);
}
}
/*
INPUT:
GeeksforGeeks
12
3.4
  
OUTPUT:
You entered integer: 12
Enter a float
You entered float: 3.4
*/

Explanation / Answer

Main.java


import java.util.Scanner;

class Main {
public static void main(String[] args) {
  
//using scanner for getting input from user
  
Scanner in = new Scanner(System.in);
  
String s = in.nextLine();
System.out.println("You entered string: "+s);
  
int a = in.nextInt();
System.out.println("You entered integer: "+a);
float b = in.nextFloat();
System.out.println("You entered float: "+b);
}
}

Output:

GeeksforGeeks
You entered string: GeeksforGeeks
12
You entered integer: 12
3.4
You entered float: 3.4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote