Problem : Write a program that takes a name from command line and say hello it? If no name is passed then display a user friendly Usage message.
Program :Step 1 - CodingCreate a text file c:\sunilos\HelloName1.java and copy below contents./* * A program which take commond line argument and check error. */ public class HelloName1 { public static void main(String[] args) { //Check length of an array. If an argument will be passed then length will be one if (args.length == 1) { System.out.println("Hello " + args[0]); } else { System.out.println("Usage : java -cp c:/sunilos HelloName1"); } } } Step 2 - Deployment
Step 3 - Testing
OutputWith argumentHello SunilOS Without argument Usage : java -cp c:/sunilos HelloName1 <<Previous | Next>> |