【发布时间】:2016-02-04 22:43:07
【问题描述】:
这是我的代码:
import java.io.PrintWriter;
import java.io.FileNotFoundException;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
String enter = "Enter";
String resolve = "Resolve";
String store = "Store";
// if file doesn't exist
int nextjob = 1;
int jobnumber = nextjob;
int phonenumber = System.console().readInt();
int numberoflines = System.console().readInt();
String problem = System.console().readLine();
int time = System.console().readInt();
String command = System.console().readLine();
if(command.equals(store)){
PrintWriter writer = new PrintWriter("openjobs.txt");
writer.println(nextjob);
writer.println(jobnumber);
writer.println(phonenumber);
writer.println(numberoflines);
writer.println(problem);
writer.println(time);
writer.close();
}
}
}
这是输出:
Main.java:14: error: cannot find symbol
int phonenumber = System.console().readInt();
^
symbol: method readInt()
location: class Console
【问题讨论】:
-
Console类中没有readInt()方法。你想让我做什么?你想读取用户输入吗? -
有什么方法可以说 readInt() 吗?我猜没有。
-
我想将用户输入读取为 int,例如 readLine()。
-
我也考虑不使用
System.console(),因为它可能会根据执行的环境返回 null。 -
使用
scanner