import java.util.Scanner; //简单模拟计算器 public class Second{ private double n1; private double n2; //构造器,初始化值,和类名相同。 public Second(double n1,double n2){ this.n1=n1; this.n2=n2; } public void addition(){ double result=n1+n2; System.out.println("n1+n2="+result); } public void subtraction(){ double result1=n1-n2; System.out.println("n1-n2="+result1); } public void multiplication(){ double result1=n1*n2; System.out.println("n1*n2="+result1); } public void division(){ double result1=n1/n2; System.out.println("n1/n2="+result1); } public static void main(String[] args){ Scanner scanner=new Scanner(System.in); System.out.println("请输入第一个数n1:"); double a = scanner.nextDouble(); System.out.println("请输入第一个数n2:"); double b= scanner.nextDouble(); Second second=new Second(a,b); second.subtraction(); second.addition(); second.multiplication(); second.division(); } }
05-17
01-17
1380