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
29 Likes
Answer
"nine:54"
"nine:9"
Working
- 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".
- 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
15 Likes
Related Questions
Answer the following:
(a) Scanner class method to accept a character.
(b) Jump statement which stops the execution of a construct.
Raj was asked to accept the phone number which has 10 digits, using the appropriate method of Scanner class. Which of the following statement he must choose?
- Ob.nextInt()
- Ob.nextDouble()
- Ob.nextLong()
- Ob.next().chatAt(0)