It tells the compiler, that any time you use a Scanner, you mean the one which is located in java.util
import java.util.Scanner;
confused about this!
Q1. What is the Scanner class in Java?
Q3. How to write a Scanner class?
Q2. What type of class is the Scanner class?
I recently started learning Java and I'm having trouble understanding how this code works -
import java.util.Scanner;
class Program {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input a number: ");
int num = in.nextInt();
System.out.printf("Your number: %d \n", num);
in.close();
}
}
Why do I need to know this?from http://mooc.cs.helsinki.fi/programming-part1/material-2013/week-1?noredirect=1
I'm confused about what scanner system does. so first
-
"import java.util.Scanner to" import the scanner system into the main body program.
-
Scanner reader = new Scanner(System.in) set scanner name as reader and creates new scanner that will parse the (system.in).
ugh I'm really confused here, they didn't really explain what each words mean, how they translate over to the next and such. I tried googling but kind of get it but no at the same time.
import java.util.Scanner;
public class Greeting {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Who is greeted: ");
String name = reader.nextLine(); // Reads a line of input from the user and assigns it
// to the variable called name
System.out.print("Hi " + name);
}}