static int bookNum;
我之前在其他代码中为bookNum做了一些事情,所以它有一个值,我已经在开头定义了它。
public static void processtrans()throws FileNotFoundException{
Scanner input = new Scanner(transFile);
String line = input.nextLine();
double dollar = 0;
int transNum = 1;
while (input.hasNextLine()) {
int Space = line.indexOf (" ");
int Space2 = line.indexOf (" ", Space + 1);
String action = line.substring(0,Space);
if (action == "ORDER"){
int Space3 = line.indexOf (" ", Space2 + 1);
String isbn = line.substring(Space + 1, Space2);
int num = Integer.parseInt(line.substring(Space2 + 1, Space3));
int custNum = Integer.parseInt(line.substring(Space3 + 1));
for (int x = 0; x < bookNum; x++){
if (bookarray[x][0] == isbn){
int stock = Integer.parseInt(bookarray[x][2]);
if (stock >= num){
stock -= num;
bookarray[x][2] = Integer.toString(stock);
System.out.println("Order filled");
}
}
}
}
line = input.nextLine();
}
}
此代码已编译但未打印任何内容,因此我开始调试它并意识到程序没有执行for
循环,它从以下位置跳转:
int custNum = Integer.parseInt(line.substring(Space3 + 1));
为:
line = input.nextLine();
有人可以帮助我吗?
答案 0 :(得分:1)
bookNum
未初始化,因此其值为0