Program to print argument length in java

22:40 Unknown 0 Comments

Below given program Show the number of arguments that how many runtime arguments you passed. Only use args.length.

//program to print argument length

class Arg_length{
                public static void main(String args[]){
                               System.out.println(args.length);
                }
}

Save program with .java extension: program_name.java
 Program_name always should main class name

For compile :
Open cmd and goto your file and type command
Javac Arg_length.java

For Run:
Java Arg_length hi hello

Output:


Here you can show only number of Arguments. If you want to print Arguments then use args[0] + args[1] and so on.

//program to print Arguments length with print Arguments.

 class Arg_length{
                public static void main(String args[]){
System.out.println("\n\t Hello Everyone!!\n Following are the value of "+args.length+ "  RunTime \n\n1)"+args[0]+"\n2)"+args[1]);
                }
}

Save program with .java extension: program_name.java
 Program_name always should main class name

For compile :
Open cmd and goto your file and type command
Javac Arg_length.java

For Run:
Java Arg_length hi friends

Output:

0 comments:

e gift