Frontend Development

Java - Simple calculator

Submitted by UBSZZZ, , Thread ID: 196826

Thread Closed
05-02-2021, 05:30 PM
#1
Code:
public static void main(String[] args) {
    // TODO code application logic here
    double o,t,mum;
    Scanner sc=new Scanner(System.in);
    System.out.print("Input number1: ");
    o = sc.nextDouble();
    System.out.print("Input +,-,*,/: ");
    mum = sc.next().charAt(0);
    System.out.print("Input number2: ");
    t = sc.nextDouble();
      if(mum == '+'){
        System.out.println("Sum : "+(o+t));    
      }else if(mum == '-'){
        System.out.println("Sum : "+(o-t));    
      }else if(mum == '*'){
        System.out.println("Sum : "+(o*t));
      }else if(mum == '/'){
        System.out.println("Sum : "+(o/t));
      }
  }

Users browsing this thread: 1 Guest(s)