Computer Applications
Write a line of code that:
i. Creates a Scanner object named scanner to be used for taking keyboard input.
ii. Uses the object scanner to read a word from the keyboard and store it in the String variable named stg.
Input in Java
10 Likes
Answer
i. Creates a Scanner object named scanner to be used for taking keyboard input.
Scanner scanner = new Scanner(System.in);
ii. Uses the object scanner to read a word from the keyboard and store it in the String variable named stg.
String stg = scanner.next();
Answered By
5 Likes
Related Questions
Consider the following input:
one, two three, four, fiveWhat values will the following code assign to the variables input1 and input2?
String input1 = keyboard.next();
String input2 = keyboard.next();Write a statement to let the user enter an integer or a double value from the keyboard.
Distinguish between the following:
hasNext() and hasNextLine()
Write a code that creates a Scanner object and sets its delimiter to the dollar sign.