×
Declaring a scanner:
Scanner in = new Scanner(new File("name.in"));
Make sure to write "throws IOException" after "main(String args[])"
Reading an integer:
int integerName = in.nextInt();
Reading a double (decimal value):
double doubleName = in.nextDouble();
Reading an entire line:
String line = in.nextLine();
There will be multiple itmes on input lines separated by spaces. You can accept the next string in a ilne of input (reading until the next whitespace character) using Scanner#next(). If you want to read the next value of a certian type (int, float, double, etc) you can use Scanner#nextInt() (or equivalent). At any point, you can then use scanner#nextLine() to accept input until the end of the line.
Attempting to read a numeric type where a string is provided will throw an error.
Scanner#nextLine() will accept the starting whitespace character from a string, and will end before the line break.
If you read to the end of a line using Scanner#nextInt() (or other numerical type getters), you will need to go to the next line using Scanner#nextLine() to prevent reading a blank value.