Challenge - 5 Problems
Command Line Arguments 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 with command line arguments?
Consider the following Java program. What will it print if run with arguments apple banana?
Java
public class Main { public static void main(String[] args) { System.out.println(args[0] + " and " + args[1]); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
What happens if no command line arguments are passed?
What will this Java program print if run without any command line arguments?
Java
public class Main { public static void main(String[] args) { if (args.length == 0) { System.out.println("No arguments"); } else { System.out.println(args[0]); } } }
Attempts:
2 left
💻 code output
advanced2:00remaining
What is the output when printing all command line arguments?
What will this Java program print if run with arguments one two three?
Java
public class Main { public static void main(String[] args) { for (String arg : args) { System.out.print(arg + "-"); } } }
Attempts:
2 left
💻 code output
advanced2:00remaining
What error occurs when accessing args without checking length?
What error will this Java program throw if run without any command line arguments?
Java
public class Main { public static void main(String[] args) { System.out.println(args[0]); } }
Attempts:
2 left
🧠 conceptual
expert3:00remaining
How to correctly parse integer command line arguments in Java?
You want to read two integer numbers from command line arguments and add them. Which code snippet correctly does this?
Attempts:
2 left
