Following Java Program will show how to take Command Line Argument in JAVA.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /************************************************************************* * * Prints "Hi, Sam. How are you?" where "Sam" is replaced by the * command-line argument. * *************************************************************************/ public class UseArgument { public static void main(String[] args) { System.out.print( "Hi, " ); System.out.print(args[ 0 ]); System.out.println( ". How are you?" ); } } /*************************** * Program Output * * % java UseArgument Bob * Hi, Bob. How are you? * * % java UseArgument Alice * Hi, Alice. How are you? ***************************/ |