Computer Science, asked by akashjain135, 1 year ago

please answer this program correctly ​

Attachments:

Answers

Answered by mn121
2

import java.util.*;

public class operator

{

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

double n1,n2,r;

char ch;

System.out.println("Enter two numbers = ");

n1 = in.nextDouble();

n2 = in.nextDouble();

System.out.println("enter + for addition, - for subtraction , * for multiplication and / for division =");

ch = (char)in.next();

switch(ch)

{

case '+': r = n1+n2;

System.out.println(n1+" + "+n2+" = "+r);

break;

case '-':

r = n1-n2;

System.out.println(n1+" - "+n2+" = "+r);

break;

case '*':

r= n1*n2;

System.out.println(n1+" * "+n2+" = "+r);

break;

case '/': r= n1/n2;

System.out.println(n1+" / "+n2+" = "+r);

break;

default :System.out.println("invalid choice");

}

}

}


mn121: please mark it as brainliest..
mn121: ^_^
mn121: sorry... there is a mistake ...
mn121: in line 13, instead of ch = (char)in.next(); it will be:
mn121: String c=in.next();
mn121: ch = c. charAt(0);
mn121: i am very sorry for my mistake ~-
Similar questions