- Home
- Output Questions for Class 10 ICSE Computer Applications
Determine the output of the following program. public class
Output Questions for Class 10 ICSE Computer Applications
Determine the output of the following program.
public class PredictOutput3
{
public static void main(String args[])
{
int a = 2, b = 2, c = 2;
System.out.println("Output 1: " + (a + 2 < b * c));
System.out.println("Output 2: " + (a + 2 < (b * c)));
}
}
Answer
Output
Output 1: false
Output 2: false
Explanation
In the first println statement, the expression is (a + 2 < b * c)
. b * c is evaluated first as * has higher precedence than + and <. After that a + 2 is evaluated as between + and <, + has higher precedence. Comparison is done in the end. As 4 < 4 is false so false is printed. The case of second println statement is similar.