writing some simple ASCII thing which basically for now is just printing out a char for each pixel with a defined width and height.
i have a for loop that adds the chars to a string and adds “\n” when width is reached so that width and height are correct.
however its currently printing one too many on first line and one too few on the last any ideas??
passing this to the method ('.', 7,5)
private String format(char character, int width, int height)
{
char[] picture = new char[width * height];
String pic = "";
for(int i = 0; i < width * height; i++)
{
picture[i] = character;
pic += picture[i];
if(i == width || i > width && i % width == 0)
{
pic += "\n";
}
}
return pic;
}
and this is my output
……..
…….
…….
…….
……
ok well each block of those dots are meant to be on different lines but for some reason its putting them in a row, anyway you can still see that first row has 8 and last row has 6?
Just move your new-line appending up in the loop:
and you should definitely use a
StringBuilderfor building strings.