5月12日学习打卡

时间:2021-07-31 11:48:49

import java.util.Scanner;

public class Calculatorup {

  int num1,num2;
  String sym;
  public Calculatorup(){
    Scanner sc = new Scanner(System.in);
    this.num1 = sc.nextInt();
    this.sym = sc.next();
    this.num2 = sc.nextInt();
  }
  public void calResults(){
  if(sym != "+" && sym != "-" && sym != "*" && sym != "/")
  {
    sym = "+";
  }
  else{
    switch( sym ){
    case "+": System.out.println(num1+num2);
    case "-": System.out.println(num1-num2);
    case "*": System.out.println(num1*num2);
    case "/": System.out.println(num1/num2);
    }
    }
  }
}

 

 

public class Main {
  public static void main(String[] args){
    Calculatorup cla = new Calculatorup();
    cla.calResults();
  }
}