if ( a > b)
System.out.println(a+b);
System.out.println (a*b);
when a = 5 and b = 7
a. 12,35
b. 35
c. 35, 12
Answers
Output:
- The output for the program is 35.
Explanation:
In the code given, there are two variables – a and b.
→ a = 5
→ b = 7
Now, let us check whether the condition given is true or false.
a > b
= 5 > 7
= false as 5 is less than 7.
So, the statement inside the if block i.e., System.out.println(a+b); will not be executed.
Now, in the next line, we have the following code:
System.out.println(a * b);
This line will be executed as it is not inside the if block.
So, the output will be:
= 5 * 7
= 35
★ Option (b) is the right answer.
Here we have been given two variables or no.s i.e they are,
a = 5
b = 7
Now let's as per the given two conditions. Moving on to the first condition,
1) System.out.printIn(a+b);
Let's assume,
Thus, the condition for System.out.printIn(a+b); is not possible.
2) System.out.printIn(a*b);
Placing values of a & b we get,
Thus, the answer for System.out.printIn(a*b); would be 35.
- Correct answer for the given question is (B) 35.