Computer Science, asked by manasraj1, 1 year ago

pls solve this Blue J question.

Attachments:

Answers

Answered by AshmitJain
2
Here is the answer :-
public class sample
{
public static void main(int a, int b, char n)
{
switch(n)
{
case '+':System.out.print("Addition = "+(a+b));
break;
case'-': System.out.print("Subtraction = "+(a-b));
break;
case'*':System.out.print("Multiplication = "+(a*b));
break;
case'/': System.out.print("Division = "+(a/b));
break;
default: System.out.print("Wrong Input");
}}}

manasraj1: can you please solve this question using if else
AshmitJain: Yes,sure!!
AshmitJain: Here's your answer with if-else :- public class sample

{

public static void main(int a, int b, char n)
{
if(n=='+')
System.out.print("Addition = "+(a+b));
else
if(n=='-')
System.out.println("Subtraction = "+(a-b));
else
if(n=='*')
System.out.print("Multiplication = "+(a*b));
else
if(n=='/')
System.out.print("Division = "+(a/b));
}
}}
manasraj1: thanks
AshmitJain: Your most welcome....
Similar questions