0

Please explain in detail about how to get user input in java

24th Dec 2016, 10:27 AM
Nitin Tiwari
Nitin Tiwari - avatar
3 Antworten
+ 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(); } }
24th Dec 2016, 2:13 PM
Boris Batinkov
Boris Batinkov - avatar
0
thanks boris batinkov can you explain what is .nextlnt ();
24th Dec 2016, 2:59 PM
Nitin Tiwari
Nitin Tiwari - avatar
0
It's expecting an integer for input. 'nextLine()' expecting a String value. The rest are obvious: 'nextByte()', 'nextShort()' and so on.
26th Dec 2016, 9:31 AM
Boris Batinkov
Boris Batinkov - avatar