나는 은행을 만들려고 노력하고 있는데, 나는 스캐너 옵션을 만들고있다. 1을 누르면 돈을 인출 할 수있다. 2를 누르면 돈을 인출 할 수있다. 그러나 2 또는 3을 누르면 아무 것도하지 않지만 다른 경우 시도했지만 더 많은 오류가 발생하고 그 차이를 알 수 없습니다.내 변수가 작동하지 않는 이유는 무엇입니까?
------ 참고 ------ 중첩을 시도했지만 (문구가있는 경우) 버튼 근처에 구문 오류가 나타납니다 (어디에서 표시했는지) 그래서 확실하지 않습니다. 그 문제를 해결하는 방법
import java.util.Scanner;
public class Bank {
public static void main (String [] args) {
System.out.println("Welcome To Harry's Bank");
//Pin System
System.out.println("Please Enter Your Bank Pin.");
Scanner userInput = new Scanner (System.in);
int number;
int password = 7123;
int amount = 4000;
number = userInput.nextInt();
if (number == password) {
System.out.println("Pin Accepted");
System.out.println("You Have Now Entered Harry's Bank!");
System.out.println("Press The Number Of The Option You Would Like.");
System.out.println("1.Withdraw Money.");
System.out.println("2.Put In Money");
System.out.println("3.Exit Bank");
Scanner Options = new Scanner (System.in);
int option;
option = userInput.nextInt();
if (option == 1) {
//Withdraw Money System
System.out.println("You Have £4000");
System.out.println("How Much Would You Like To Take Out?");
Scanner Input = new Scanner (System.in);
int numbere;
numbere = userInput.nextInt();
if (numbere < 4000) {
int money = amount - numbere;
System.out.println("You Have Now £" + money);
System.out.println("Thank You For Banking At Harry's Bank!");
System.out.println("Please Come Again!");
}else{
System.out.println("You Do Not Have Enough Money!");
}
}
else if (option == 2) {
//AddMoney System
Scanner AddMoney = new Scanner (System.in);
int AddMoney1;
AddMoney1 = userInput.nextInt();
int NewMoney = (amount + AddMoney1);
System.out.println("How Much Would You Like To Enter?");
System.out.println("You Now Have " + NewMoney + "!");
System.out.println("Thank You For Using Harry's Bank!");
}
else if (option == 3) {
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("Goodbye!");
}
}else{
System.out.println("Next Time Only Press 1,2 or 3!");
}
//error Here For Else "Syntax error on token "else", { expected"
}else{
System.out.println("Pin Declined!");
}
}
}
적절한 코드 들여 쓰기가 솔루션을 즉시 보여줬을 것입니다. –