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));
        }
    }
  • 相关阅读:
    Smobiler 仿知乎APP个人主页
    smobiler仿自如app筛选页面
    Smobiler 仿美柚APP个人主页
    谈谈网络协议 – 物理层
    谈谈网络协议 – 路由
    谈谈网络协议 – 基础知识
    Flutter(三):Flutter App 可行性分析
    Flutter(二):编写第一个Flutter App
    Flutter(一):MAC的Flutter安装指南
    Jetpack新成员,Paging3从吐槽到真香
  • 原文地址:https://www.cnblogs.com/lhy8116/p/14183750.html
Copyright © 2011-2022 走看看