控制台计算器-有BUG版

import java.util.Scanner;
 public class z1{
     public static void main(String args[]){
         Scanner scanner=new Scanner(System.in);

         System.out.println("请输入第一个数字:");
         double one=scanner.nextDouble();
         System.out.println("请输入第二个数字:");
         double two=scanner.nextDouble();
         System.out.println("请选择运算符:");
         System.out.println("1:加 2:减 3:乘 4:除");
         double operator=scanner.nextDouble();


         double result=0;
         double remainder=0;

         switch((int)operator){

             case 1:
                 result=one+two;
                 break;
             case 2:
                 result=one-two;
                 break;
             case 3:
                 result=one*two;
                 break;
             case 4:
                 result=one/two;
                 remainder=one%two;
                 break;
         }
         if (operator==4){
             System.out.println("结果为:"+result+"余数为:"+remainder);
         }else
             System.out.println("结果为:"+result);
         scanner.close();
     }
 }

 

posted @ 2022-09-21 16:58  xiaoyongdata  阅读(21)  评论(0编辑  收藏  举报