I'm having some trouble getting the correct output when printing an array. Essentially what I'm trying to do is set up an array in the main method, then send that array to another method that would print out something like this:
89 12 33 7 72 42 76 49
69 85 61 23
With it being 3 spaces to the right and starting a new print line after the 8th number. Seems easy enough but I get something like this instead.
89
69 85 61 23
It doesn't print out the values between position 1 and 7 for some reason. This is what I have.
public class Test
{
public static void main (String [] args)
{
int [] myInches = {89,12,33,7,72,42,76,49,69,85,61,23};
printArrayValues(myInches);
}
public static void printArrayValues(int [] myInchesParam) {
for (int i = 0; i < 8; i++) {
System.out.print(" " + myInchesParam[i]);
System.out.println();
for (i = 8; i < 12; i++) {
System.out.print(" " + myInchesParam[i]);
}
}
}
}
Should I use a do-while instead? Or can I still do it with a for loop and I'm just doing it wrong?
ito 8 in the inner loop.}to close off your first loop before your second one starts.forloop to after the first one. Alternatively, get rid of the innerforloop, have the outer one loop through all the values and haveSystem.out.printlnonly ifi % 8 === 7.iis already defined in first loop