2015-10-24 51 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)