2013-05-03 57 views
0

我正在試着做一個銀行,我正在製作一個掃描儀選項,所以如果你按1你可以提取錢,如果你按2你會增加錢和3下車銀行。但是當我按2或3時,它什麼都不做,我試過其他的,但是然後我得到更多的錯誤,我不知道它們的區別。爲什麼我的變量不起作用?

------ NOTE ------ 我試過un嵌套(如果多數民衆贊成在一個短語)他們,但我得到一個語法錯誤附近的按鈕(我已標記在哪裏)其他所以我不知道如何解決這個問題

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!"); 

      } 



      } 








     } 
+6

正確的代碼縮進將立即顯示解決方案:) – 2013-05-03 19:53:51

回答

1

因爲第3和第4條if語句是遙不可及的。如果你不按1,他們將永遠達不到。

8

括號內爲空。你有

if(option ==1) 
{ 
    if(option == 2) 
    { 
     //stuff 
    } 

    if(option == 3) 
    { 
     //stuff 
    } 
} 

搬完IFS出側第一

0

你有你的,如果嵌套如果「選項== 1」,所以你不能達到的選項2或3的內部聲明,這應該是其他鏈如果是