Monday, February 2, 2015

Hello Name - 2

3. Write a program in java to print "Hello Name" using command line argument with taking care of possible runtime exception.

class User{
     public static void main(String[]  args){
         String name = "";
         if(args.length==1)name = args[0];
         System.out.println("Hello "+name);

After compilation, run this program as follows and watch the output in next line:
prompt>java User Amit
Hello Amit

prompt>java User

No comments:

Post a Comment