0

how does scanner work

7th Nov 2016, 9:11 PM
Jakob Ban
Jakob Ban - avatar
2 Answers
+ 4
when java scanner just scans the user input or the thing you specified to scan(scan = analysis or read) and takes it or located it to where you want it to be stored; E.g: telling scanner to take user input and place some where; Scanner sc = Scanner (System.in)//system.in is saying that you are taking input String name; System.out.println("Enter you name: "); name = sc.next();//this is telling it to place the user input into this variable. E.g setting scanner to be a variable: String str = " abcdefghijklmnopqrstuvwxyz"; Scanner sc = new Scanner(str);
7th Nov 2016, 9:29 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
0
Scanner sc = new Scanner(System.in); int c = sc.nextInt(); sc.close(); above code will wait until the user enters a Integer. after user enter the integer it will assign it to c; similarly, other data types can also be read..
8th Nov 2016, 4:48 AM
Akash Middinti