這是一些我寧願弄清楚自己的工作,所以你可以請不要直接給出答案,但也許可以指出我正確的方向爲什麼我我正在從循環輸出接收錯誤,以及爲什麼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()'調用試圖超過輸入文件的末尾? –