Java program to take inputs from the user
ADVERTISEMENTS
Java program to take inputs from the user. There are you will learn how to take inputs from the user in the Java language.
Let us understand this example through the Java program:
// Java program to take inputs from the user
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the integer value::\n");
int p = in.nextInt();
System.out.println("Enter the float value::\n");
float q = in.nextFloat();
System.out.println("Enter the string value::\n");
char r = in.next().charAt(0);
// Output
System.out.println("\nThe integer input is:\n" + p);
System.out.println("\nThe float input is:\n" + q);
System.out.println("\nThe string input is:\n" + r);
}
}
Output:
Enter the integer value::
5
Enter the float value::
7.5
Enter the string value::
h
The integer input is:
5
The float input is:
7.5
The string input is:
h