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
52 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
25 Likes
Related Questions
Write a program to input two unequal numbers. Display the numbers after swapping their values in the variables without using a third variable.
Sample Input: a=23, b= 56
Sample Output: a=56, b=23Write a program to input the temperature in Celsius and convert it into Fahrenheit. If the temperature is more than 98.6 °F then display "Fever" otherwise "Normal".
Write a program to accept marks of a student obtained in 5 different subjects (English, Phy., Chem., Biology, Maths.) and find the average. If the average is 80% or more then he/she is eligible to get "Computer Science" otherwise "Biology".
'Mega Market' has announced festival discounts on the purchase of items, based on the total cost of the items purchased:
Total cost Discount Up to ₹2,000 5% ₹2,001 to ₹5,000 10% ₹5,001 to ₹10,000 15% Above ₹10,000 20% Write a program to input the total cost. Display name of the customer, discount and the amount to be paid after discount.