The following program demonstrates how to Display All Command Line Arguments in a Loop in Java.

When the user executes the following program without providing any argument at the command line, it displays the message ‘No Value’. Otherwise, it displays all the command line arguments in a for loop separated by a comma.

public class Exercise3
{
	public static void main(String[] args) {
		int n1;
		if(args.length==0)
			System.out.println("No Value!");
		else
		{
			for(String n:args)
			{
				System.out.print(n+", ");
			}
		}
	}
}

Output

A Program to Display All Command Line Arguments in a Loop in Java
A Program to Display All Command Line Arguments in a Loop in Java

Further Reading

Java Practice Exercise

programmingempire

Princites