Computer Applications
Give the output of the snippet:
int a=10,b=12;
if(a==10&&b<=12)
a--;
else
++b;
System.out.println(a + "and" +b);
Java
Java Conditional Stmts
53 Likes
Answer
9and12
Working
As a is 10 and b is 12 so the condition of if is true. a is decremented by 1, b remains unchanged.
Answered By
25 Likes
Related Questions
Rewrite the snippet using Ternary operators:
if(a<b) { c=(a+b); } else { c=(a-b); }
Predict the output:
int a=6,b=5; a += a++ % b++ *a + b++* --b;
Give the output of the snippet:
int p = 9; while (p<=15) { p++; if(p== 10) continue; System.out.println(p); }
An Electricity Board charges for electricity per month from their consumers according to the units consumed. The tariff is given below:
Units Consumed Charges Up to 200 units ₹3.80/unit More than 200 units and up to 300 units ₹4.40/unit More than 300 units and up to 400 units ₹5.10/unit More than 400 units ₹5.80/unit Write a program to calculate the electricity bill taking consumer's name and units consumed as inputs. Display the output.