KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Predict the output of the given snippet, when executed:

int a=1,b=1,m=10,n=5;
if((a==1)&&(b==0))
{
System.out.println((m+n)); 
System.out.println((m-n));
}
if((a==1)&&(b==1))
{
System.out.println((m*n)); 
System.out.println((m%n));
} 

Java

Input in Java

50 Likes

Answer

50
0

Working

The condition of the statement if((a==1)&&(b==0)) evaluates to false as b is not equal to 0. Statements inside its block are not executed. Condition of next if statement if((a==1)&&(b==1)) is true as both a and b are 1. So statements in its block are executed, printing the result of m*n (10 * 5 = 50) and m%n (10 % 5 = 0) as the output.

Answered By

24 Likes