Creating a user name input and greeting message program

Report a typo

Consider a simple interaction program in Java. You want to prompt the user to input their name through the console window and then output a greeting message with the user's name included. You may use the Scanner class for the task. Fill the blanks in the code to complete this program correctly and efficiently.

Fill in the gaps with the relevant elements
import java.util.;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ("Enter your name: ");
        String name = sc.();
        System.out.println("Your name is: " + name);
    }
}
nextLineScannerSystem.out.println
___

Create a free account to access the full topic