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));
        }
    }
  • 相关阅读:
    手写堆排序和归并排序
    海量数据处理
    HDU 1532 --&&-- POJ1273 dinic 算法
    POJ 3159 最短路 SPFA
    POJ 1459 网络流 EK算法
    8.14比赛j题 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87813#overview
    单链表---邻接表
    poj 1273 ---&&--- hdu 1532 最大流模板
    HDU 2603 二分匹配
    UVA 796 连通图求桥
  • 原文地址:https://www.cnblogs.com/lhy8116/p/14183750.html
Copyright © 2011-2022 走看看