写计算器,加减乘除功能,能循环接收新的数据,通过用户交互实现

写计算器,加减乘除功能,能循环接收新的数据,通过用户交互实现,第1张

写计算器,加减乘除功能,能循环接收新的数据,通过用户交互实现
package com.Astero.method;

import java.util.Scanner;



public class HomeWork01 {
   public static void add() {//这里是加法哟!
       Scanner cj = new Scanner(System.in);
       int x = cj.nextInt();    //键盘获取x
       int y = cj.nextInt();    //键盘获取y
       System.out.println((x+y));//输出结果
   }

   public static void minus() {//这里是减法哟!
       Scanner cj = new Scanner(System.in);
       int x = cj.nextInt();    //键盘获取x
       int y = cj.nextInt();    //键盘获取y
       System.out.println((x-y));//输出结果
   }

    public static void mul() {//这里是乘法哟!
        Scanner cj = new Scanner(System.in);
        int x = cj.nextInt();    //键盘获取x
        int y = cj.nextInt();    //键盘获取y
        System.out.println((x*y));//输出结果
    }

    public static void div() {//这里是除法哟!
        Scanner cj = new Scanner(System.in);
        int x = cj.nextInt();    //键盘获取x
        int y = cj.nextInt();    //键盘获取y
        System.out.println((x/y));//输出结果
    }

    public static void main(String[] args) {
        System.out.println("欢迎使用Asteroidea测试算法呐!");
        System.out.println("**********************************");
        for (int i = 0; i < 100; i++) {
            System.out.println("1.加法运算:");
            System.out.println("2.减法运算:");
            System.out.println("3.乘法运算:");
            System.out.println("4.除法运算:");
            System.out.println("*********************");
            System.out.println("请选择您运算功能的序号:");

            Scanner cj = new Scanner(System.in);
            int x = cj.nextInt();//从键盘输入x
            switch (x) {
                case 1:
                    System.out.println("请输入加法的两位数:");
                    add();//按键1的时候调用了add(加)方法
                case 2:
                    System.out.println("请输入减法的两位数:");
                    minus();//按键2的时候调用了minus(减)方法
                case 3:
                    System.out.println("请输入乘法的两位数:");
                    mul();//按键3的时候调用了mul(乘)方法
                case 4:
                    System.out.println("请输入除法两位数:");
                    div();//按键4的时候调用了div(除)方法
                    break;
            }
        }
    }
}
运行结果如下:

欢迎使用Asteroidea测试算法呐!
**********************************
1.加法运算:
2.减法运算:
3.乘法运算:
4.除法运算:
*********************
请选择您运算功能的序号:
1
请输入加法的两位数:
2
3
5
请输入减法的两位数:
88
66
22
请输入乘法的两位数:
3
6
18
请输入除法两位数:
56
2
28

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5687362.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存