0
Please explain in detail about how to get user input in java
3 Respuestas
+ 1
import java.util.Scanner; // Imports the scanner utility
public class SomeClass {
public static void main(String[] args) {
Scanner inputSomething = new Scanner(System.in); // Creates an object of type 'Scanner' named 'inputSomething'
// Declaring variable 'someVar' of type integer and waits for user's input
int someVar = inputSomething.nextInt();
// Prints the content of the integer variable
System.out.println(someVar);
// You can close the scanner, if not used anymore
inputSomething.close();
}
}
0
thanks boris batinkov
can you explain what is .nextlnt ();
0
It's expecting an integer for input.
'nextLine()' expecting a String value.
The rest are obvious: 'nextByte()', 'nextShort()' and so on.