这是我的代码:
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
答案 0 :(得分:4)
使用Scanner
和Scanner.nextInt()
方法仅将Integer作为用户的输入。
Scanner sc = new Scanner(System.in);
int anyNumber = sc.nextInt();
如果用户提供的输入不是整数,则会抛出InputMismatchException
。