public class Calculator {
public static void main(String[] args) {
NumCal nc = new NumCal(6, 2);
nc.addition();
nc.subtraction();
nc.multiplication();
nc.division();
}
}
class NumCal {
private int n1;
private int n2;
public NumCal(int n1, int n2) {
this.n1 = n1;
this.n2 = n2;
}
public int getN1() {
return n1;
}
public void setN1(int n1) {
this.n1 = n1;
}
public int getN2() {
return n2;
}
public void setN2(int n2) {
this.n2 = n2;
}
public void addition() {
System.out.println(this.n1 + " + " + this.n2 + " = " + (this.n1 + this.n2));
}
public void subtraction() {
System.out.println(this.n1 + " - " + this.n2 + " = " + (this.n1 - this.n2));
}
public void multiplication() {
System.out.println(this.n1 + " * " + this.n2 + " = " + (this.n1 * this.n2));
}
public void division() {
System.out.println(this.n1 + " / " + this.n2 + " = " + (this.n1 / this.n2));
}
}
javase:简单计算器
最新推荐文章于 2024-10-06 20:16:20 发布