✏️ Explanatory Question

Complete the code below to create an object of Scanner class:

Scanner sc = ____ Scanner(__________);

👁 164 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

To complete the code for creating an object of the Scanner class, you need to import the Scanner class and use the new keyword to instantiate it. Here is the completed code:


import java.util.Scanner;

Scanner sc = new Scanner(System.in);

In this code:

  • import java.util.Scanner; imports the Scanner class from the java.util package.
  • new Scanner(System.in) creates a new Scanner object that reads input from the standard input stream (System.in).