2014-03-25 164 views
0

我得到我的return語句「非法字符‘\ u600b’爲下面的代碼固定的「非法字符‘U \ 600B’」的錯誤:需要幫助的Java

public static int getNum() { 
    Scanner in = new Scanner(System.in); 
    int number; 
    boolean goodInput = true;  
    do { 
     goodInput = true; 
     try { 
      System.out.print("Please enter a positive number: "); // prompts the user 
      number = Integer.parseInt(in.nextLine()); // Tries to make the next input a number 
     } catch (Exception e) { // if it breaks 
      System.out.println("The number you entered was invalid."); // it tells the user it was wrong 
      goodInput = false; // and runs the loop again 
     } 
     if(number <= 0) { // makes sure that the number entered was valid 
      System.out.println("The number you entered was invalid."); 
      goodInput = false; // or it re runs the loop 
     } 
    }while (!goodInput) 

    ​return number; 

} 

任何一個知道如何解決這個問題?

+1

我知道這可能聽起來很奇怪,但是你可以刪除return語句之前和之後的行以及return語句,然後重新鍵入它嗎? (複製粘貼可能不起作用) – hexafraction

+0

^^那。你有垃圾,不可打印的字符,你從某處複製和粘貼。 –

+0

該死的,這是很奇怪的錯誤,我試圖重現它,它「工作」,但我不知道爲什麼! – libik

回答

2

在看着您的文章的降價源,我發現了一個流浪的非打印字符的return之前。你需要刪除整條生產線並重復輸入(或刪除字符本身)。

如果將光標放在r和e之間,然後按< -有幾次,您會看到光標不會移動其中一次。