Complete the code to read an integer from the user using Scanner.
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number = scanner.[1](); System.out.println("You entered: " + number); } }
The nextInt() method reads an integer value from the user input.
Complete the code to create a Scanner object to read input from the keyboard.
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner [1] = new Scanner(System.in); } }
Variable names can be anything, but scanner is a common and clear choice.
Fix the error in the code to correctly read an integer from the user.
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number = scanner.[1](); System.out.println("Number: " + number); } }
The method nextInt() reads an integer. Using nextLine() or others causes errors or wrong types.
Fill both blanks to read an integer and print it with a message.
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner [1] = new Scanner(System.in); int num = [2].nextInt(); System.out.println("You typed: " + num); } }
Using the same variable name scanner to create and then call nextInt() is correct.
Fill all three blanks to read two integers and print their sum.
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner [1] = new Scanner(System.in); int a = [2].nextInt(); int b = [3].nextInt(); System.out.println("Sum: " + (a + b)); } }
Use the same Scanner variable scanner to read both integers.
