Bird
0
0

What is the output of the following Java code?

medium📝 Predict Output Q13 of 15
Java - Command Line Arguments

What is the output of the following Java code?

String s = "123";
int num = Integer.parseInt(s);
System.out.println(num + 10);
A12310
B133
CError: cannot parse string
D10
Step-by-Step Solution
Solution:
  1. Step 1: Parse string to integer

    Integer.parseInt("123") converts string "123" to integer 123.
  2. Step 2: Add 10 to parsed integer

    Adding 10 to 123 results in 133.
  3. Final Answer:

    133 -> Option B
  4. Quick Check:

    123 + 10 = 133 [OK]
Quick Trick: Parsed number + 10 means numeric addition [OK]
Common Mistakes:
  • Thinking output is string concatenation '12310'
  • Assuming parseInt throws error on valid input
  • Confusing print output with input string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes