2015-10-24 49 views
1

< = opperator工作不工作......給我的錯誤不知道爲什麼操作不if語句和掃描儀

Scanner age = new Scanner(System.in); 
     String age1 = age.nextLine(); 
     System.out.println("How old are you?"); 
     if (age1 <= 20) 

      System.out.println("Access granted"); 
     } 
+1

'age1'是字符串。閱讀更多關於如何從掃描儀讀取的教程。提示_nextInt_ :) – sam

回答

1

什麼喲有有一個字符串。你需要解析它。

嘗試Integer.parseInt(age1)