首页 文章

二元运算符的错误操作数类型'>'

提问于
浏览
-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 回答

  • 1

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

相关问题