循环+switch计算器练习

import java.util.Scanner;

public class Cacula {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //循环用户输入的数据
        while(true){
            System.out.println("请输入第一个数字:");
            int firstnum = scanner.nextInt();
            System.out.println("请输入方式");
            String metho = scanner.next();
            System.out.println("请输入第二个数字");
            int secondnum = scanner.nextInt();
            switch (metho){
                case "+":
                    System.out.println(firstnum+secondnum);
                    break;
                case "-":
                    System.out.println(firstnum-secondnum);
                    break;
                case "*":
                    System.out.println(firstnum*secondnum);
                    break;
                case "/":
                    System.out.println(firstnum/secondnum);
                    break;
            }
        }
    }

    //加
    public static int sum(int i,int j){
        return i+j;
    }
    //减
    public static int sub(int i,int j){
        return i-j;
    }
    //乘
    public static int mul(int i,int j){
        return i*j;
    }
    //除
    public static int div(int i,int j){
        return i/j;
    }

}

循环+switch计算器练习

上一篇:CentOS7 更新最新内核 | RPM直接安装内核


下一篇:iOS手势UIGestureRecognizer