2015-09-03 82 views
-1

我在我的代码的这一行中收到错误。二元运算符'>'的不良操作数类型

if (age < 17) { 
     System.out.println("You are a adult"); 

的错误是错误的操作数类型的二元运算符“>”

这是我的全部代码

package transition.work; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 

/** 
* 
* @author New 
*/ 
public class TransitionWork { 

    /** 
    * @param args the command line arguments 
    * @throws java.io.IOException 
    */ 
    public static void main(String[] args) throws IOException { 
     System.out.println("Hello, what is your name?"); 

     InputStreamReader inputStreamReader = new InputStreamReader(System.in); 
    BufferedReader reader = new BufferedReader(inputStreamReader); 
    System.out.println("Type name:"); 
    String name = reader.readLine(); 
    System.out.println("Hello "+name+", How old are you?"); 
    String age; 
     age = reader.readLine(); 

    if (age < 17) { 
     System.out.println("You are a adult"); 
     } 

    } 
} 

预先感谢您的帮助! :)

回答

1

我的猜测是你正在比较age(一个字符串变量)到17(一个整数文字)。尝试使用Integer.parseInt()age转换为整数。

相关问题