zoukankan      html  css  js  c++  java
  • 写一个计算器,要求实现加减乘除功能,能够循环接收收据,通过用户交互实现

    
    import java.util.Scanner;
    
    public class Demo{
        public static void main(String[] args) {
            for (int i = 0; i < 50; i++) {
                Scanner sc = new Scanner(System.in);
                System.out.println("===============================");
                System.out.println("1.加法运算");
                System.out.println("2.减法运算");
                System.out.println("3.乘法运算");
                System.out.println("4.除法运算");
                System.out.println("===============================");
                System.out.println("请输入您要选择的计算方法提示数字:");
                int a = sc.nextInt();
                switch (a) {
                    case 1:
                        System.out.println("请输入您的两个数字:");
                        add();
                        break;
                    case 2:
                        System.out.println("请输入您的两个数字:");
                        subtract();
                        break;
                    case 3:
                        System.out.println("请输入您的两个数字:");
                        multiplication();
                        break;
                    case 4:
                        System.out.println("请输入您的两个数字:");
                        division();
                        break;
                    default:
                        System.out.println("请输入数字!!!!!");
                }
            }
        }
        //加法
        public static void add() {
            Scanner sc1 = new Scanner(System.in);
            int s1 = sc1.nextInt();
            int s2 = sc1.nextInt();
            System.out.println("运算结果是:" + (s1 + s2));
        }
        //减法
        public static void subtract() {
            Scanner sc2 = new Scanner(System.in);
            int s1 = sc2.nextInt();
            int s2 = sc2.nextInt();
            System.out.println("运算结果是:" + (s1 - s2));
        }
        //乘法
        public static void multiplication() {
            Scanner sc3 = new Scanner(System.in);
            int s1 = sc3.nextInt();
            int s2 = sc3.nextInt();
            System.out.println("运算结果是:" + (s1 * s2));
        }
        //除法
        public static void division() {
            Scanner sc4 = new Scanner(System.in);
            int s1 = sc4.nextInt();
            int s2 = sc4.nextInt();
            System.out.println("运算结果是:" + (s1 / s2));
        }
    }
  • 相关阅读:
    LabelImg 图像图像标注工具
    周杰伦的2000w个故事
    ROS 订阅图像节点(1)
    ROS 订阅图像节点
    ROS 双目标定
    书籍
    Z30云台PC控制问题
    大疆M600组装和试飞
    M100 X3云台安装
    M100 组装教程
  • 原文地址:https://www.cnblogs.com/lhy8116/p/14183750.html
Copyright © 2011-2022 走看看