我在这行代码中遇到错误。
if (age < 17) {
System.out.println("You are a adult");
错误是二元运算符'&gt;'
的错误操作数类型这是我的完整代码
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");
}
}
}
提前感谢您的帮助! :)
答案 0 :(得分:1)
我的猜测是你将### a
(字符串变量)与age
(整数字面值)进行比较。尝试使用17
将age
转换为整数。