Java 浅做计算器
package www.nihao; import java.util.Scanner; public class counter { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("请输入两个操作数:"); int number1 = scanner.nextInt(); int number2 = scanner.nextInt(); System.out.println("请选择你要计算的法则:"); System.out.println("1.加法"); System.out.println("2.减法"); System.out.println("3.乘法"); System.out.println("4.除法"); int rule = scanner.nextInt(); switch (rule) { case 1: System.out.println(add(number1, number2)); break; case 2: System.out.println(minus(number1, number2)); break; case 3: System.out.println(multiply(number1, number2)); break; case 4: System.out.println(division(number1, number2)); break; default: return;} scanner.close(); } public static int add(int a,int b){ int sum; sum=a+b; return sum; } public static int minus(int a,int b){ int sum; sum=a-b; return sum; } public static int multiply(int a,int b){ int sum; sum=a*b; return sum; } public static int division(int a,int b){ int sum; sum=a/b; return sum; } }