zoukankan      html  css  js  c++  java
  • 简单计算器

    public class Cal {

     

        /**

         * @param args

         */

        public static void main(String[] args) {

            // TODO Auto-generated method stub

            Scanner i = new Scanner(System.in);

            System.out.println("输入一个数");

            int a = i.nextInt();

            System.out.println("输入二个数");

            int b = i.nextInt();

            System.out.println("输入运算符");

            String s = i.next();

     

            if (s.equals("+")) {

                int sum;

                sum = a + b;

                System.out.println(sum);

            } else if (s.equals("-")) {

                int sum;

                if (a < b) {

                    sum = b - a;

                    System.out.println(sum);

                } else if (a > b) {

                    sum = a - b;

                    System.out.println(sum);

                }

            } else if (s.equals("*")) {

                int sum;

                sum = a * b;

                System.out.println(sum);

            } else if (s.equals("/")) {

                if (a < b) {

                    int sum;

                    sum = b / a;

                       if(a==0){

                      System.out.println(“除数需不为0”);

                     }

                    System.out.println(sum);

                } else if (a > b) {

                    int sum = a / b;

                    System.out.println(sum);

     

                }

            }

     

        }

    }

  • 相关阅读:
    趣图:程序员告诉你为什么充钱后速度更快
    金三银四铜五铁六,面试得做好这个准备
    Java中如何模拟真正的同时并发请求?
    趣图:程序员最头疼的原因
    Java并发面试题
    linux内存分配与回收
    7.3 Set集合
    7.2 Java 11新增的Collection和Iterator接口
    7.1 Java集合概念
    6.5 正则表达式
  • 原文地址:https://www.cnblogs.com/xiaoqingtest/p/5313797.html
Copyright © 2011-2022 走看看