KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Predict the output of the following Java program code snippet:

int m=3,n=5,p=4;
if(m==n && n!=p)
{
System.out.println(m*n);
System.out.println(n%p);
}
if((m!=n) || (n==p))
{
System.out.println(m+n);
System.out.println(m-n);
}

Java

Java Conditional Stmts

ICSE

63 Likes

Answer

8
-2

Working

The first if condition — if(m==n && n!=p), tests false as m is not equal to n. The second if condition — if((m!=n) || (n==p)) tests true so the statements inside its code block are executed printing 8 and -2 to the console.

Answered By

31 Likes