2016-01-16 40 views
0

我是Java新手。我在讀這本書以編程的介紹使用Java V7和發現問題,這樣的代碼:TextIO.getln()沒有得到輸入?

public class CreateProfile { 

    public static void main(String[] args) { 
    // TODO Auto-generated method stub 
     String name; 
     String email; 
     double salary; 
     String favColor; 

     TextIO.putln("Good Afternoon! This program will create"); 
     TextIO.putln("your profile file, if you will just answer"); 
     TextIO.putln("a few simple questions."); 
     TextIO.putln(); 

     /* Gather responses from the users. */ 


     TextIO.put("What is your name?  "); 
     name = TextIO.getln(); 
     TextIO.put("What is your email address?  "); 
     email = TextIO.getln(); 
     TextIO.put("what is your salary income?  "); 
     salary = TextIO.getDouble(); 
     TextIO.putln(); 
     TextIO.put("What is your favorite color?  "); 
     favColor = TextIO.getln(); 

     /* Write the user's information to the file named profile.txt. */ 

     TextIO.writeFile("profile.txt"); //subsequent output goes to file 
     TextIO.putln("Name:  " + name); 
     TextIO.putln("Email: " + email); 
     TextIO.putln("Favorite Color: " + favColor); 
     TextIO.putf("Yearly Income:  %1.2f%n", salary); 

     /* Print a final message to standard output. */ 

     TextIO.writeStandardOutput(); 
     TextIO.putln("Thank you. Your profile has been written to profile.txt."); 

    } 
} 

控制檯不要求我輸入最喜歡的顏色而是直接跳轉到寫文件的過程。

enter image description here

,當我把favColor輸入語句工資之前,似乎有沒有問題: enter image description here

誰能請解釋一下我爲什麼?

+0

你濫用javers標籤,請刪除它(只留下java) –

+0

嗨,什麼是javers標籤?我相信我只使用了帶有TextIO類的Java? – Rubit

+0

好的我想我知道你在說什麼。謝謝。 – Rubit

回答

0

嘗試刪除TextIO.putln();

TextIO.put("What is your name?  "); 
name = TextIO.getln(); 
TextIO.put("What is your email address?  "); 
email = TextIO.getln(); 
TextIO.put("what is your salary income?  "); 
salary = TextIO.getDouble(); 
//TextIO.putln(); 
TextIO.put("What is your favorite color?  "); 
favColor = TextIO.getln(); 

問候。

+0

嗨,我嘗試刪除它,但問題仍然存在。 – Rubit