2016-03-02 151 views
0

我寫了一個簡單的基於條目的程序,掃描器正在跳過它。我嘗試了過去幫助過的各種方法,但無濟於事。我感謝所有幫助。掃描器跳過條目

下面的代碼是我的主要方法中的所有代碼。

Scanner scan = new Scanner(System.in); 

    ArrayList <String> list = new ArrayList <String> (); 



    System.out.println("You can choose any of the following:"); 
    System.out.println("\n - Add: Add an element to the Array List."); 
    System.out.println("\n - Numbered Remove: Remove an element by it's placement in the Array List."); 
    System.out.println("\n - Named Remove: Remove an element by name."); 
    System.out.println("\n - Clear: Clear the entire Array List"); 
    System.out.println("\n - Search: Find a specific element, and the amount of occurences in the Array List."); 
    System.out.println("\n - Find Size: Prints the size of each element in the Array List."); 
    System.out.println("\n - Print: Prints the entire Array List."); 
    System.out.println("\n - Quit: Quits the program."); 

    System.out.println(); 
    System.out.println(); 

    System.out.println("Type the FIRST word of each listing EXACTLY in order to continue."); 
    System.out.print("--> "); 
    String program = scan.nextLine(); 

    String prgm = program.toLowerCase(); 

    if (prgm == "add") 
    { 
     add(list); 
    } 


    if (prgm == "numbered") 
    { 
     numbered(list); 
    } 


    if (prgm == "named") 
    { 
     named(list); 
    } 


    if (prgm == "clear") 
    { 
     clear(list); 
    } 


    if (prgm == "search") 
    { 
     search(list); 
    } 


    if (prgm == "find") 
    { 
     find(list); 
    } 


    if (prgm == "print") 
    { 
     print(list); 
    } 


    if (prgm == "quit") 
    { 
     System.out.println("Goodbye."); 
    } 



    String prgm = program.toLowerCase(); 
+0

什麼是確切的問題? scan是如何定義的?你想打印出'prgm'嗎? –

+0

輸出用於各種if循環來調用不同的方法。我的掃描儀是「掃描儀掃描=新掃描儀(System.in);」。我不希望打印prgm,只是爲了查看它是否與任何設置的響應相匹配。 – arsb48

+2

沒有看到更多的代碼,並確切地知道問題是什麼,我會大膽猜測,並說'scan.next()'而不是'scan.nextLine()' –

回答