0
0
Javaprogramming~10 mins

Using Scanner class in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Scanner object to read input from the keyboard.

Java
Scanner scanner = new [1](System.in);
Drag options to blanks, or click blank then click option'
AInputStream
BScanner
CSystem
DBufferedReader
Attempts:
3 left
💡 Hint
Common Mistakes
Using InputStream instead of Scanner to create the object.
Trying to use System directly as a class to create Scanner.
2fill in blank
medium

Complete the code to read an integer value from the user using Scanner.

Java
int number = scanner.[1]();
Drag options to blanks, or click blank then click option'
AnextInt
BnextLine
CnextDouble
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Using nextLine() which reads a whole line as a string.
Using nextDouble() when expecting an integer.
3fill in blank
hard

Fix the error in the code to read a string input from the user.

Java
String name = scanner.[1]();
Drag options to blanks, or click blank then click option'
AnextIntLine
BnextDouble
CnextInt
DnextLine
Attempts:
3 left
💡 Hint
Common Mistakes
Using nextInt() or nextDouble() which expect numbers.
Using a non-existent method like nextIntLine().
4fill in blank
hard

Fill both blanks to read a double value and then close the Scanner.

Java
double value = scanner.[1]();
scanner.[2]();
Drag options to blanks, or click blank then click option'
AnextDouble
Bclose
CnextInt
DnextLine
Attempts:
3 left
💡 Hint
Common Mistakes
Using nextInt() instead of nextDouble() for double values.
Forgetting to close the Scanner.
5fill in blank
hard

Fill all three blanks to read a string, an integer, and then print them.

Java
String name = scanner.[1]();
int age = scanner.[2]();
System.out.println([3] + ": " + age);
Drag options to blanks, or click blank then click option'
AnextLine
BnextInt
Cname
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Using next() instead of nextLine() for reading the name.
Printing a variable that was not declared.