Results 1 to 4 of 4
Thread: Trouble with an array/loop
- 02-05-2013, 04:28 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Trouble with an array/loop
My code is:
public class Homework12 {
int array1[];
int arraySize;
int output;
int arrayValue;
int loop;
public void setRange()
{
arraySize = 15;
}
public void createArray()
{
array1 = new int[arraySize];
}
public void fillArray()
{
arrayValue = 0;
loop = 1;
do
{
array1[arrayValue] = loop;
System.out.println(array1[loop]);
arrayValue++;
loop++;
}
while (arrayValue <= (arraySize+1)); //?????
}
as you can see, I print out the value of array1[loop], which seems like it should increase by one every time. However, it instead just posts the value of 0 every time. Also, I did a println of array1[arrayValue] in the same place as the current print line and it gradually increased like it was supposed to. Anybody have any idea why?
Thanks
- 02-05-2013, 04:34 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Re: Trouble with an array/loop
Look at the index in the array you are filling and the index in the array you are displaying... Are they the same?
- 02-05-2013, 04:42 PM #3
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
Re: Trouble with an array/loop
Beaten to it :(
- 02-05-2013, 07:43 PM #4
Member
- Join Date
- Feb 2013
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
trouble placing a loop in code
By james75 in forum New To JavaReplies: 1Last Post: 07-08-2012, 09:20 PM -
For loop trouble
By 2wyked in forum New To JavaReplies: 7Last Post: 03-27-2011, 05:50 PM -
Trouble with for loop
By subiedude101 in forum New To JavaReplies: 4Last Post: 02-13-2011, 09:27 PM -
trouble with loop
By aamster in forum New To JavaReplies: 10Last Post: 10-16-2009, 09:18 PM -
[SOLVED] Trouble with this loop!
By PureAwesomeness in forum New To JavaReplies: 35Last Post: 02-02-2009, 07:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks