-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");
        }  

    }
}

预先感谢您的帮助!:)

4

1 回答 1

1

我的猜测是您正在将age(字符串变量)与17(整数文字)进行比较。尝试age使用 转换为整数Integer.parseInt()

于 2015-09-03T21:42:05.753 回答