+ 3

How do you get the scanner working on java?

Anybody know

16th Mar 2018, 4:24 AM
Codeguy
2 odpowiedzi
+ 2
Well to start, you first need to import the library that contains the scanner for Java: import java.util.Scanner; Next, you would need to declare a variable with data type Scanner creating a new instance of the Scanner class, and System.in as a parameter: Scanner x = new Scanner(System.in);
16th Mar 2018, 4:58 AM
Faisal
Faisal - avatar
+ 2
At the beginng you must to import the Java.util.Scanner;. If you have finished, you can use the Scanner with: Scanner sc = new Scanner(System.in);. You can scan a nummber with int x = sc.nextInt(); If you want to scan a text, you can do that with: String s = sc.next(); If you are finished to use the scanner you MUST to use the command sc.close();
17th Mar 2018, 10:34 PM
AntiminiZwerg