Modify the program such that if there are no command line


Consider the following Java program:

import java.lang.*;
public class SecondProgram {
public static void main ( String args[] ) {
if (args.length > 0) {
System.out.println("Hello " + args[0]);
} else {
System.out.println( "Hello everybody!");
}
}
}

PART 1.

Modify the program such that if there are no command line arguments, when you type:

java SecondProgram

It should give:

Hello everybody!

PART 2:

If there are command line arguments (names) then it will print Hello to all the names with one name printed per line (along with the number of the name):

When you type:

java SecondProgram Helen Armen Joseph

You should get:

Hello
1. Helen
2. Armen
3. Joseph

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Modify the program such that if there are no command line
Reference No:- TGS01249747

Now Priced at $20 (50% Discount)

Recommended (95%)

Rated (4.7/5)