double[] IndividualAccumulatesArray;
for (int i=1;i<=Employees;i++)
{
IndividualAccumulatesArray = new double[i];
System.out.println("\n");
System.out.print("What is the Accumulated Earning's for Employee #"+i+"? $");
IndividualAccumulatesArray[i] = reader.nextDouble();
所以我在for循环中创建了IndividualAcculates数组但是我想保持每个数组的值,以便它可以在另一个for循环中使用
while(Confirm.equalsIgnoreCase("yes"))
{
for (int i=1;i<=Employees;i++)
{
System.out.println("\n");
System.out.print("How Much Dose Employee #"+i+" Get This Pay Period? $");
PayCheck = reader.nextDouble();
if (IndividualAccumulatesArray[i]>=7000)
{
因为它表示变量IndividualAccumulatesArray
可能尚未针对第二个for循环
答案 0 :(得分:2)
如果要创建一个您不知道初始大小的动态数组。
使用ArrayList
代替
现在的问题是,在进入for循环之前,你没有初始化数组。这意味着它可能永远不会被初始化。
如果数组的大小需要是Employees的数量。
double[] IndividualAccumulatesArray = new double[Employees];
for (int i=1;i<=Employees;i++)
{
System.out.println("\n");
System.out.print("What is the Accumulated Earning's for Employee #"+i+"? $");
IndividualAccumulatesArray[i] = reader.nextDouble();
答案 1 :(得分:0)
您只需声明变量但不要初始化数组,只需使用Employees初始化它,如下所示:
double[] IndividualAccumulatesArray = new double[Employees];