Heads up, this is a small small part of a school project, and as such i have tried keep from asking you guys to simply write the code for me.
as a back ground: I am trying to populate this char[][] array in a spiral manner, i think i have an algorithm that will work, however, as often the case is... its not working.
But right now I am having trouble getting my code to enter and execute in this for loop. here is a small snippet...
In this specific example I am running k is a char[] array that is length 10
and pT is a char[] array of length 92
box2 = new char[height][k.length];
int c = 0;
int limit = pT.length; //ensures the while loop doesint attempt to populate past the array bounds
int w = k.length; //width of array
int h = height; //height of array
//these two variable i am trying to use to count how many blocks are
//filled on the outside of the spiral.
//example.. as the spiral populates inward, it can no longer travel the entire
//length of the array, but one less block for every pass
int difH = 0; //difference in height
int difW = 0; //difference in width
while (limit > 0) {
for (int n = 0; n < (w - (w - difW)); n++) {
box[h - (h - difH)][n] = pT[c];
limit--;
}
}
for whatever reason when I step through the code in netbeans it does not enter or execute this for loop, or any of the other three.
Can anyone help me figure out why my code wont enter or execute this loop?
In case you wish to see the entire while loop:
while (limit > 0) {
for (int n = 0; n < (w - (w - difW)); n++) {
box[h - (h - difH)][n] = pT[c];
limit--;
}
difH--;
for (int n = h - (h - difH); n > 0; n--) {
box[n][w - (w - difW)] = pT[c];
limit--;
}
difW--;
for (int n = w - (w - difW); n > 0; n--) {
box[h - (h - difH)][n] = pT[c];
limit--;
}
difH--;
for (int n = 0; n < h - (h - difH); n++) {
box[n][w - (w - difW)] = pT[c];
limit--;
}
difW--;
}
//Prints box2
//prints the box array
int counter2 = 0;
for (int column = 0; column < box2.length; column++) {
if (column > 0) {
System.out.print("|");
}
System.out.println();
for (int r = 0; r < box2[column].length; r++) {
System.out.print("|" + box2[column][r]);
}
}
System.out.println("|\n");
If I am screwed up beyond all understandability (as is entirely possible), please just let me know and i will edit or maybe reevaluate my algorithm.
System.out.println(n)and so on in case of Java, so you know what is going on and can construct the logic how the program works in your head, and will see if somewhere is wrong number.