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
1import java.util.*;
2class a
3{
4 void main ()
5 {
6 Scanner in = new Scanner(System.in);
7 System.out.print("Please enter you age: ");
8 int age = in.nextInt();
9 System.out.print("Please enter today's date: ");
10 int date = in.nextInt();
11 System.out.print("Please enter current month: ");
12 int month = in.nextInt();
13 System.out.print("Please enter current year: ");
14 int year = in.nextInt();
15 }
16}
17// ENJOY!!!!!!!
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}
1import java.util.Scanner;
2...
3 Scanner console = new Scanner(System.in);
4 int num = console.nextInt();
5 console.nextLine() // to take in the enter after the nextInt()
6 String str = console.nextLine();
1//For continues reading a line
2import java.util.Scanner;
3
4Scanner in = new Scanner(System.in);
5while(in.hasNextLine()) {
6 String line = in.nextLine();
7 System.out.println("Next line is is: " + line);
8}