简易计算机

public static void main(String[] args) {
System.out.println("欢迎使用简易计算器");
System.out.println("请你输入第一个数字");
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
System.out.println("请你再输入第二个数字");
int y = scanner.nextInt();
System.out.println("请输入符号+-*/");
String code = scanner.next();
GuoruijiaTest test = new GuoruijiaTest();
test.setX(x);
test.setY(y); 
test.setCode(code); 
System.out.println("得出这个数字是:"+test.setCode(code));

}



                            Test

public class XXXXXXX{

                private int x;
private int y;
private String code;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public String getCode() {
return code;
}
public int setCode(String code) {
this.code = code;
switch (code) {
case "+":

return x+y; 
case "-":
return x-y;
case "求和" :
int sum = 0;
for (int i =0;i<y; i++){
sum+=i;

}

return sum;
case"*":
return x*y;

case "最大值":
return Math.max(x, y);
case "最小值":
return Math.min(x, y);
}
return 0;
}






扫描二维码关注公众号,回复: 170885 查看本文章


猜你喜欢

转载自blog.csdn.net/g1448261713/article/details/77152380