Complete the code to print the first command line argument.
public class Main { public static void main(String[] args) { System.out.println([1]); } }
args instead of args[0] to print the first argument.The first command line argument is accessed using args[0].
Complete the code to check if any command line arguments were passed.
public class Main { public static void main(String[] args) { if ([1] > 0) { System.out.println("Arguments passed"); } else { System.out.println("No arguments"); } } }
args[0] to check length instead of args.length.The number of command line arguments is given by args.length.
Fix the error in the code to correctly print all command line arguments.
public class Main { public static void main(String[] args) { for (int i = 0; i < [1]; i++) { System.out.println(args[i]); } } }
args.size() or args.length() which are invalid for arrays.The correct way to get the number of elements in the args array is args.length.
Fill both blanks to create a program that sums two integer command line arguments.
public class Main { public static void main(String[] args) { int num1 = Integer.[1](args[0]); int num2 = Integer.[2](args[1]); System.out.println(num1 + num2); } }
valueOf which returns an Integer object, not int.Use Integer.parseInt() to convert string arguments to integers.
Fill all three blanks to create a program that prints command line arguments in uppercase if they exist.
public class Main { public static void main(String[] args) { if (args.[1] > 0) { for (int i = 0; i < args.[2]; i++) { System.out.println(args[i].[3]()); } } else { System.out.println("No arguments"); } } }
size instead of length for arrays.Use args.length to get the number of arguments and toUpperCase() to convert strings to uppercase.
