Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the first command line argument.
Java
public class Main { public static void main(String[] args) { System.out.println([1]); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to check if any command line arguments were passed.
Java
public class Main { public static void main(String[] args) { if ([1] > 0) { System.out.println("Arguments passed"); } else { System.out.println("No arguments"); } } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in the code to correctly print all command line arguments.
Java
public class Main { public static void main(String[] args) { for (int i = 0; i < [1]; i++) { System.out.println(args[i]); } } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
4fill in blank
hardFill both blanks to create a program that sums two integer command line arguments.
Java
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); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill all three blanks to create a program that prints command line arguments in uppercase if they exist.
Java
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"); } } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
