• 简单计算器


    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);

     

                }

            }

     

        }

    }

  • 相关阅读:
    【leetcode】416. Partition Equal Subset Sum
    【leetcode】893. Groups of Special-Equivalent Strings
    【leetcode】892. Surface Area of 3D Shapes
    【leetcode】883. Projection Area of 3D Shapes
    【leetcode】140. Word Break II
    【leetcode】126. Word Ladder II
    【leetcode】44. Wildcard Matching
    【leetcode】336. Palindrome Pairs
    【leetcode】354. Russian Doll Envelopes
    2017.12.22 英语面试手记
  • 原文地址:https://www.cnblogs.com/xiaoqingtest/p/5313797.html
Copyright © 2020-2023  润新知