0

(Scanner)I dont really understand whats happening here and i use this alot.

import java.util.Scanner; //this imports scanner object right? String x; // x is telling system that x is a string // Scanner scan = new Scanner(System.in); //scan is telling the system that scan is the scanner object// x = scan.next(); /*this is the part i dont get if x is now scan why do i ask systrem to print (x)?*/ //im assuming .next(); means after input read next line? System.out.println(x); // this retuns the input of x which is now a scanner?

11th Jun 2017, 4:01 PM
D_Stark
D_Stark - avatar
3 ответов
+ 4
*You create a Scanner, get input from the user and print it. next() basically means to read the next word of input from the user. This would be until there's a space. x = scan.next() is not making x a scanner. x is now whatever is returned from the next() method. Which is a String. x = scan; is what would set x to a scanner. But this would throw an error since you can't convert a String to a Scanner. The last line doesn't 'return' anything, it is only printing what the value of x is.
11th Jun 2017, 4:17 PM
Rrestoring faith
Rrestoring faith - avatar
0
Edit the line x = scan.nextLine(); it's telling java that "read the keyboard input as a string .."
11th Jun 2017, 4:04 PM
suryapoojary
suryapoojary - avatar
0
in Java, Scanner is a class name in Java.util package. basically used for input data from keyboard.
11th Jun 2017, 4:23 PM
meherDev
meherDev - avatar