1import java.util.Scanner; /* Required Import*/
2public class reading{
3 public static void main(String[] args){
4 Scanner scan = new Scanner(System.in); // Create Reader
5 System.out.print("Enter Your Age"); // Ask the user for something
6 int age = scan.nextInt(); // Read value from user
7 System.out.print(age); // Output the value
8 }
9}
10/*
11 Java Reading Options:
12 1_ reading int => nextInt();
13 2_ reading char => next().charAt(0); Single Character
14 3_ reading string => next();
15 4_ reading double => nextDouble();
16*/
1Scanner sc = new Scanner(System.in); // Create a Scanner object
2String userName = sc.nextLine();//read input string
3int age = sc.nextInt(); //read input integer
4long mobileNo = sc.nextLong(); //read input long
5double cgpa = sc.nextDouble(); //read input double
6System.out.println(userName);//output
1Scanner sc = new Scanner(System.in);
2String s = sc.next();
3int n = sc.nextInt();
4double d = sc.nextDouble();
5float f = sc.nextFloat();
6
7// more fast way
8BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9String s = br.readLine(); // read line
10int c = br.read(); // read single char
1import java.util.*;
2class UserInputDemo
3{
4public static void main(String[] args)
5{
6Scanner sc= new Scanner(System.in); //System.in is a standard input stream
7System.out.print("Enter first number- ");
8int a= sc.nextInt();
9System.out.print("Enter second number- ");
10int b= sc.nextInt();
11System.out.print("Enter third number- ");
12int c= sc.nextInt();
13int d=a+b+c;
14System.out.println("Total= " +d);
15}
16}