電卓を作ろうとしています。これらの演算子: x
、+
、-
、正常に/
動作します。
しかし、ユーザーが数学の問題の答えを得た後、2 つのことを実行できるようにしたいと考えています。
続行するかどうかをユーザーに尋ねます。
- ユーザー
yes
が入力すると、再びカウントされる2つの数字を入力できます。 - ユーザーが
no
単にシャットダウンした場合。
これが私のコードです:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner Minscanner = new Scanner(System.in);
int nr1 = Integer.parseInt(Minscanner.nextLine());
int nr2 = Integer.parseInt(Minscanner.nextLine());
int yes = Integer.parseInt(Minscanner.nextLine());//trying to fix reset
int ans =0;
int reset = J;/trying to make it reset if user types in yes
String anvin = Minscanner.nextLine();
if(anvin.equalsIgnoreCase("+")) {
ans = nr1 + nr2;
}
else if(anvin.equalsIgnoreCase("-")) {
ans = nr1 - nr2;
}
else if(anvin.equalsIgnoreCase("*")) {
ans = nr1 * nr2;
}
else if(anvin.equalsIgnoreCase("/")) {
ans = nr1 / nr2;
System.out.println(ans);
}
if(anvin.equalsIgnoreCase("yes")) {
return;
}
}
}