简单计算器

 

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

 

            }

        }

 

    }

}

posted @ 2016-03-24 00:02  forever0316  阅读(124)  评论(0编辑  收藏  举报