这是一些我宁愿弄清楚自己的工作,所以你可以请不要直接给出答案,但也许可以指出我正确的方向为什么我我正在从循环输出接收错误,以及为什么IF语句没有生成输出。对于循环错误 - >如果语句不产生输出
我必须允许用户输入'推荐的最高员工工资',然后从不同商店单元的文件中读取文本以计算每个商店单位的员工工资和总员工成本。
这里是我要读
Unit One
4
32 8
38 6
38 6
16 7
Unit Two
0
Unit Three
2
36 7
36 7
Unit Four
6
32 6.5
32 6.5
36 6.5
36 6.5
38 6.5
38 6.5
...continued up to 9 shop units.
文本这是我的代码:
public class Recursion {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count =0;
int n = 1;
int t=0;
int triangularNumber =0;
while (n<Integer.MAX_VALUE)
{
t = isTriangularNumber(n,count,triangularNumber);
triangularNumber=0;
int starNumber= ((6*n)*(n-1)) + 1;
if (starNumber ==t)
{
System.out.println(t);
}
n++;
}
if (n==Integer.MAX_VALUE)
{
System.exit(0);
}
}
public static int isTriangularNumber(int n, int count, int triangularNumber)
{
triangularNumber =triangularNumber + (n-(n-count));
if (count<=n)
{
return isTriangularNumber(n,(count++), triangularNumber);
}
else return triangularNumber;
}
} 为铺台的打印输出都很好,但它的输出后产生一个错误,并且if语句的输出不出来,如下所示:
Please enter the recommended maximum staff cost:
900
You entered: 900.0
256.0
484.0
712.0
824.0
The total staff cost of Unit One is £824.0
The total staff cost of Unit Two is £0.0
252.0
504.0
The total staff cost of Unit Three is £504.0
208.0
416.0
650.0
884.0
1131.0
1378.0
The total staff cost of Unit Four is £1378.0
208.0
464.0
688.0
944.0
The total staff cost of Unit Five is £944.0
266.0
461.0
653.0
845.0
1037.0
The total staff cost of Unit Six is £1037.0
The total staff cost of Unit Seven is £0.0
480.0
The total staff cost of Unit Eight is £480.0
192.0
348.0
543.0
711.0
935.0
The total staff cost of Unit Nine is £935.0
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at TEST.main(TEST.java:48)
任何想法可能会造成这种情况?
粗略猜测:你的两个'infile.nextLine()'调用试图超过输入文件的末尾? –