1import java.util.Scanner;
2
3// import scanner
4
5Scanner myScanner = new Scanner(System.in); // Make scanner obj
6
7String inputString = myScanner.nextLine(); // Take whole line
8
9boolean inputBoolean = myScanner.nextBoolean(); //Boolean input
10
11long inputLong = myScanner.nextLong(); //Interger,long ... input
1import java.util.Scanner;
2
3Public class Scanner {
4 Public static void main(String[] args) {
5 // Scanner *scanner name here* = new Scanner(System.in);
6 Scanner scan = new Scanner(System.in);
7 System.out.println("Type anything and the scanner will take that input and print it");
8 String next = scan.next();
9 System.out.println(next);
10 }
11}
1import java.util.Scanner;//import Scanner
2
3Scanner input=new Scanner(System.in);//Create the scanner Obj
4
5float numF = input.nextFloat();//Returns float
6int num1 = input.nextInt(); //Returns int
7byte byte1 = input.nextByte();//Returns Byte
8long lg1 = input.nextLong();//Returns long
9boolean b1 = input.nextBoolean();//Returns bool
10double num2 = input.nextDouble();//Returns Double
11String nome = input.nextLine();//Returns String
12
13//execution is pause until you give input
14
15
1// import Scanner
2import java.util.Scanner;
3
4// Initialize Scanner
5Scanner input = new Scanner(System.in);
6
7// Test program with Scanner
8System.out.println("What is your name?");
9String name = input.nextLine();
10
11System.out.println("Hello," + name + " , it is nice to meet you!");
1import java.util.Scanner;
2public class AddTwoNumbers2 {
3
4 public static void main(String[] args) {
5
6 int num1, num2, sum;
7 Scanner sc = new Scanner(System.in);
8 System.out.println("Enter First Number: ");
9 num1 = sc.nextInt();
10
11 System.out.println("Enter Second Number: ");
12 num2 = sc.nextInt();
13
14 sc.close();
15 sum = num1 + num2;
16 System.out.println("Sum of these numbers: "+sum);
17 }
18}
19
20Output: