Bird
0
0

What will be the output when running this Java program with arguments: java Example red blue?

medium📝 Predict Output Q4 of 15
Java - Command Line Arguments
What will be the output when running this Java program with arguments: java Example red blue?
public class Example {
  public static void main(String[] args) {
    System.out.println(args[0] + " and " + args[1]);
  }
}
Aargs[0] and args[1]
Bred blue
Cred and blue
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand command-line arguments

    Arguments passed are stored in args array, so args[0] is "red" and args[1] is "blue".
  2. Step 2: Analyze print statement

    The program concatenates args[0], the string " and ", and args[1].
  3. Final Answer:

    red and blue -> Option C
  4. Quick Check:

    args array holds command-line inputs in order [OK]
Quick Trick: args[0] is first argument, args[1] second [OK]
Common Mistakes:
  • Confusing args array with input strings
  • Assuming args are space-separated in output
  • Expecting compilation error due to syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes