While this looks like a book problem... I'll answer cause I think its fun LOL I'm retarded.
Anyway I think this is how it works without looking at anythingz
Here's teh code I documented.. I think with it you can change variables/methods in anyway
int cMax = 5; //max columns
int rMax = 5; //max rows
int columns = 0; //current column count
int rows = 0; //current row count
while (rows < rMax) { //runs 5 times (0, 1, 2, 3, 4) --using starting index of 0
if (columns == cMax) { //if we hit 6 columns (if 0 == 5) 0, 1, 2, 3, 4, 5
System.out.println(); //output newline
columns = 0; //reset column count
rows++; //next row
} else {
if (rows == 0 || rows == rMax - 1) { //if starting or at end of row
for (columns = 0; columns < cMax; columns++) { //output * 5 times ( if columns < 5 || 0, 1, 2, 3, 4 )
System.out.print("*"); //put asterisk
}
} else { //if in the middle rows ( 1, 2, 3 )
if (columns >= 1 && columns <= cMax -2) { //if we are in the middle columns ( 1, 2, 3 )
System.out.print(" "); //put space
columns++; //next column
} else { //if we are in the outside columns ( 0, 4 )
System.out.print("*"); //put asterisk
columns++; //next column
}
}
}
}
Example with current cmax and rmax values of 5, replacing space with underscore for space formatting
*****
*___*
*___*
*___*
*****
While this looks like a book problem... I'll answer cause I think its fun LOL I'm retarded.
Anyway I think this is how it works without looking at anythingz
Here's teh code I documented.. I think with it you can change variables/methods in anyway
int cMax = 5; //max columns
int rMax = 5; //max rows
int columns = 0; //current column count
int rows = 0; //current row count
while (rows < rMax) { //runs 5 times (0, 1, 2, 3, 4) --using starting index of 0
if (columns == cMax) { //if we hit 6 columns (if 0 == 5) 0, 1, 2, 3, 4, 5
System.out.println(); //output newline
columns = 0; //reset column count
rows++; //next row
} else {
if (rows == 0 || rows == rMax - 1) { //if starting or at end of row
for (columns = 0; columns < cMax; columns++) { //output * 5 times ( if columns < 5 || 0, 1, 2, 3, 4 )
System.out.print("*"); //put asterisk
}
} else { //if in the middle rows ( 1, 2, 3 )
if (columns >= 1 && columns <= cMax -2) { //if we are in the middle columns ( 1, 2, 3 )
System.out.print(" "); //put space
columns++; //next column
} else { //if we are in the outside columns ( 0, 4 )
System.out.print("*"); //put asterisk
columns++; //next column
}
}
}
}
Example with current cmax and rmax values of 5, replacing space with underscore for space formatting
*****
*___*
*___*
*___*
*****
Yep, you got it for the most part :P
Although, since the values are already at 0, they are not accounted for when we do column++ or row++, so there is only 5.
1,2,3,4,5
The cool part about it though, is that you can replace the cMax and rMax values for the number of columns and rows, respectively, making it dynamic and resizable while keeping the same properties (an empty star square).
With a few adjustments it could be used to title any text that you input to it, and it could easily be converted to C++ (I'll post it in the OP in a few minutes.)
Well done :P