KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Give the output of the following program segment:

System.out.println("nine:" + 5 + 4);
System.out.println("nine:" + (5 + 4));

Java

Input in Java

ICSE

22 Likes

Answer

"nine:54"
"nine:9"

Working

  1. First "nine:" + 5 is evaluated. As one operand of addition operator is string so implicit conversion converts 5 to string and concatenates it with "nine:" and the result is "nine:5". Next "nine:5" + 4 is evaluated and similarly it results in "nine:54".
  2. Due to brackets, first (5 + 4) is evaluated. As both operands are numeric so arithmetic addition takes place resulting in 9. Next "nine:" + 9 is evaluated and results in "nine:9".

Answered By

13 Likes