gpt4 book ai didi

java - 跳过运行 for 循环

转载 作者:行者123 更新时间:2023-12-01 13:16:09 24 4
gpt4 key购买 nike

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();

有人可以帮助我吗?

最佳答案

bookNum 未初始化,因此其值为 0

关于java - 跳过运行 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22448616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com