Advertisements
Advertisements
प्रश्न
Convert the following construct as directed:
switch case construct into if-else-if:
switch(n)
{
case 1:
s = a + b;
System.out.println("Sum = " + s);
break;
case 2:
d = a − b;
System.out. println("Difference = " + d);
break;
case 3:
p = a * b;
System.out.println("Product = " + p);
break;
default:
System.out.println("Wrong Choice!");
}
संक्षेप में उत्तर
उत्तर
if (n == 1)
{s = a + b;
System.out.printIn("Sum = " + s);
}
else if (n == 2)
{d = a − b;
System.out.printIn("Difference = " + d);
}
else if (n == 3)
{p = a * b;
System.out.printin("Product = " + p);
}
else
System.out.printIn("Wrong Choice");
}
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1.08: Conditional Statements in Java - EXERCISES [पृष्ठ ९९]