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
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
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}