Challenge - 5 Problems
Argument Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
What is the output of this Java program?
Consider the following Java program that accesses command-line arguments. What will it print when run with arguments:
java Main Hello World?Java
public class Main { public static void main(String[] args) { System.out.println(args[0] + " " + args[1]); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
What happens if no arguments are passed?
What will be the output or result of running this Java program with no command-line arguments?
Java
public class Main { public static void main(String[] args) { System.out.println(args.length); System.out.println(args[0]); } }
Attempts:
2 left
🔧 debug
advanced2:00remaining
Identify the error in accessing arguments
This Java program tries to print all command-line arguments but throws an error. What is the cause?
Java
public class Main { public static void main(String[] args) { for (int i = 1; i <= args.length; i++) { System.out.println(args[i]); } } }
Attempts:
2 left
📝 syntax
advanced2:00remaining
Which option correctly accesses the last argument?
Given a Java program with command-line arguments, which code snippet correctly prints the last argument?
Attempts:
2 left
🚀 application
expert2:00remaining
What is the output of this program with arguments: java Main 5 10 15?
This Java program sums integer command-line arguments. What does it print when run with arguments
5 10 15?Java
public class Main { public static void main(String[] args) { int sum = 0; for (String arg : args) { sum += Integer.parseInt(arg); } System.out.println(sum); } }
Attempts:
2 left
