第四章 第5题

时间:2020-11-29 22:11:51
Scanner input = new Scanner(System.in);
  System.out.println("请输入第一个操作数:");
  double num1 = input.nextDouble();
  System.out.println("请输入第二个操作数:");
  if (input.hasNextDouble() == true) {
   double num2 = input.nextDouble();
   System.out.println("请输入:1加法,2减法,3乘法,4除法");
   int c = input.nextInt();
   switch (c) {
   case 1:
    System.out.println("计算结果:" + (num1 + num2));
    break;
   case 2:
    System.out.println("计算结果:" + (num1 - num2));
    break;
   case 3:
    System.out.println("计算结果:" + (num1 * num2));
    break;
   case 4:
    System.out.println("计算结果:" + (num1 / num2));
    break;
   default:
    System.out.println("无此选项!");
    break;
   }
  } else {
   System.out.println("请输入正确数字!");
  }