package 本章总结; public class A01class { public int ope(int Operator, int num1, int num2) { switch (Operator) { case 1: num1 += num2; break; case 2: num1 -= num2; break; case 3: num1 *= num2; break; case 4: num1 /= num2; break; default: System.out.println("输入有误!重新输入:"); A01 A = new A01(); A.main(null); break; } System.out.println("运算结果:" + num1); return num1; } } package 本章总结; import java.util.Scanner; public class A01 { public static void main(String[] args) { // TODO Auto-generated method stub A01class A01 = new A01class(); Scanner in = new Scanner(System.in); System.out.print("请选择运算: 1.加法 2.减法 3.乘法 4.除法:"); int Operator = in.nextInt(); System.out.print("请输入第一个数:"); int num1 = in.nextInt(); System.out.print("请输入第二个数:"); int num2 = in.nextInt(); A01.ope(Operator, num1, num2); } }
java-第十三章-类的无参方法(一)-代参方法的编程计算器,布布扣,bubuko.com
时间: 2024-12-17 11:36:52