well one problem is there is a logic error in the code. Specifically on line 106.
Code:
for(int k = 0; k <= 20; k++){
list[k] = distanceTravel;
}
Quote:
|
I've tried that before but it didn't work. I think the problem maybe adding the values from distanceTravel into the array. I have no idea how to do that!
|
If you want to add values to any array all you have to do is an assignment statement just like you would add an int or anything to that matter.
So if you wanted to add to the first element you would do.
Code:
ar[0] = distanceTraveled;
If you wanted to add to the second element:
Code:
ar[1] = distanceTraveled;
And so forth and so forth. If you wanted to add to the next empty element in the array then you would have to keep track of which one that is. Starting at zero and incrementing the number up each time you enter something into the array.
As far as beginning java code goes that's the best solution. Later you'll learn how to enter an unlimited (well virtually unlimited) amount of data into a list. But that is for a later date.