Greeting user by name or printing a default message

Report a typo

You are working on a simple Java program that should greet the user if their name is specified as the application's parameter, otherwise it should print 'Hello, world!' to the console. The program should be launched from the command line. Fill the blanks in the code so that it behaves according to the requirements.

Fill in the gaps with the relevant elements
  Main {
    public static void (String[] args){
        if(args.length>0){
            ("Hello, " + args[0] + "!");
        }
        else {
            System.out.println("Hello, world!");
        }
    }
}
mainclassSystem.out.printlnpublic

Create a free account to access the full topic