我正在尝试读取一个文件并将该文件中的内容写入几个不同的文本文件中,但我无法让程序写入任何内容,因为我相信我需要在此处插入一个 nextLine() ,但是我不知道在哪里。我是这个网站的新手,也是java的新手。请帮忙。
while (readFile.hasNext())
{
m = readFile.nextLine();
p = readFile.nextLine();
double cos = readFile.nextDouble();
double bof = readFile.nextDouble();
profit = bof - cos;
if (profit >= bb)
{
bold.println(m + " " + p + " " + formatter.format(profit));
}
else if (profit >= ss && profit <= bb)
{
solid.println(m + " " + p + " " + formatter.format(profit));
}
else if (profit >= eS && profit <= ss)
{
odd.println(m + " " + p + " " + formatter.format(profit));
}
else
{
flo.println(m + " " + p + " " + formatter.format(profit));
}
}
最佳答案
您应该在读取 double 后消耗行尾:
m = readFile.nextLine();
p = readFile.nextLine();
double cos = readFile.nextDouble();
double bof = readFile.nextDouble();
readFile.nextLine();
关于java - 如何在 while 循环内的 nextLine 之后使用 nextDouble,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28777517/