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(args[[1]]); } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to check if any arguments were passed.
Java
public class Main { public static void main(String[] args) { if (args.[1] > 0) { System.out.println("Arguments received."); } 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 print all arguments using a for loop.
Java
public class Main { public static void main(String[] args) { for (int i = 0; i < args.[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 print the last argument safely.
Java
public class Main { public static void main(String[] args) { if (args.[1] > 0) { System.out.println(args[args.[2] - 1]); } else { System.out.println("No arguments."); } } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill all three blanks to print all arguments in uppercase.
Java
public class Main { public static void main(String[] args) { for (int [1] = 0; [2] < args.[3]; [1]++) { System.out.println(args[[1]].toUpperCase()); } } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
