计算器实现
package com.lei;import java.util.*;public class JiSuan { /** * 属性 */ Scanner input = new Scanner(System.in); double num1; double num2; /** * 方法 */ public double suan() { double num3 = 0; System.out.print("请输入序号:1(+)2(-)3(*)4(/):"); int open = input.nextInt(); switch(open) { case 1: num3 = num1+num2; System.out.println(num1+ "+"+num2+"="+num3); break; case 2: num3 = num1-num2; System.out.println(num1+ "-"+num2+"="+num3); break; case 3: num3 = num1*num2; System.out.println(num1+ "*"+num2+"="+num3); break; case 4: num3 = num1/num2; System.out.println(num1+ "/"+num2+"="+num3); break; default: System.out.println("输入错误"); break; } return num3; }}
package com.lei;import java.util.*;public class JiSuan2 { public static void main(String[] args) { JiSuan suan = new JiSuan(); Scanner input = new Scanner(System.in); do { System.out.println("请输入第一个数:"); suan.num1 = input.nextDouble(); System.out.println("请输入第二个数:"); suan.num2 = input.nextDouble(); suan.suan(); }while(true); }}