
Java Scanner input
Quiz by Michael Engel
Feel free to use or edit a copy
includes Teacher and Student dashboards
Measure skillsfrom any curriculum
Measure skills
from any curriculum
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
With a free account, teachers can
- edit the questions
- save a copy for later
- start a class game
- automatically assign follow-up activities based on students’ scores
- assign as homework
- share a link with colleagues
- print as a bubble sheet
16 questions
Show answers
- Q1Which method can be used to retrieve an integer input from the user using the Scanner class?nextLinenextIntnextBooleannextDouble30s
- Q2Which method is used to retrieve a string input from the user using the Scanner class?nextBooleannextDoublenextLinenextInt30s
- Q3Which method can be used to retrieve a double input from the user using the Scanner class?nextBooleannextIntnextDoublenextLine30s
- Q4How can you create an instance of the Scanner class to read user input from the console?Scanner scanner = new Scanner(System.out);Scanner scanner = new Scanner(System.console());Scanner scanner = new Scanner(System.in);Scanner scanner = new Scanner();30s
- Q5Which method can be used to read a character input from the user using the Scanner class?nextIntnext().charAt(0)nextBooleannextLine30s
- Q6What will be the result of casting a double to an int in Java?The result will be zero.The decimal portion will be truncated.The value will be rounded to the nearest integer.The value will be increased by 1.30s
- Q7What happens when you cast a boolean to an int in Java?It is not possible to cast a boolean to an int in Java.The boolean value true is converted to 1 and false is converted to 0.The boolean value true is converted to -1 and false is converted to 0.The result will be a random integer value.30s
- Q8What happens when you cast a char to an int in Java?The result will be a random integer value.It is not possible to cast a char to an int in Java.The character is converted to its uppercase representation as the int value.The ASCII value of the character is returned as the int value.30s
- Q9What is the purpose of casting in Java?To change the value of a variable.To convert a primitive data type to an object.To convert a value from one data type to another.To perform arithmetic operations.30s
- Q10Which of the following is true about casting primitives in Java?Casting is always safe and doesn't cause any issues.Casting can only be done between compatible types.Casting is only used for converting numeric types.Casting can result in loss of data or precision.30s
- Q11Which of the following is NOT a primitive type in Java?Stringbooleanintdouble30s
- Q12What is the difference between parseInt and parseDouble in Java?There is no difference between parseInt and parseDouble.parseInt parses a double while parseDouble parses an integer.parseInt parses a string to an integer while parseDouble parses a string to a double.parseInt parses an integer while parseDouble parses a double.30s
- Q13Which of the following is true about parseInt and parseDouble in Java?parseDouble can handle decimal numbers while parseInt cannot.parseInt and parseDouble can both handle decimal numbers.parseInt can handle decimal numbers while parseDouble cannot.Both parseInt and parseDouble can handle decimal numbers.30s
- Q14Which method should you use to convert a string to an integer in Java?parseIntparseStringconvertIntparseInteger30s
- Q15When should you use parseInt instead of parseDouble in Java?When you want to convert an integer to a string.When you want to convert a double to a string.When you want to convert a string to a double.When you want to convert a string to an integer.30s