How would you setup the Scanner object How might it get diff

How would you setup the Scanner object? How might it get different types of data from the keyboard? Can you guys give some examples of how to get integer, double, and string input from the keyboard?

Solution

How would you setup the Scanner object

Answer: Scanner scan = new Scanner(System.in);

How might it get different types of data from the keyboard? Can you guys give some examples of how to get integer, double, and string input from the keyboard?

Answer:

System.out.println(\"Enter an integer: \");

int intNum = scan.nextInt();

System.out.println(\"Enter a double value: \");

double doubleNum = scan.nextDouble();

System.out.println(\"Enter a string: \");

String s = scan.next();

How would you setup the Scanner object? How might it get different types of data from the keyboard? Can you guys give some examples of how to get integer, doubl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site