What is the right syntax to read an integer from the user in Java?
2024
What is the right syntax to read an integer from the user in Java?
- A.
Scanner sc = new Scanner(System.in); int num = sc.readInt();
- B.
Scanner sc = new Scanner(System.in); int num = sc.inputInt();
- C.
Scanner sc = new Scanner(System.in); int num = sc.nextInt();
- D.
Scanner sc = new Scanner(System.in); int num = sc.getInt();
- E.
Question not attempted
Attempted by 65 students.
Show answer & explanation
Correct answer: C
With a Scanner object, nextInt() is the Java method used to read an integer value from the user.