I am having an issue breaking down my logic into code. The task is to draw a circle represented with *'s.
My code currently:
void main() {
String size = IO.readln("How big do you want this circle? ");
// First half of the circle
for (int row = 1; row <= Integer.parseInt(size); row++) {
for (int i = 0; i < Integer.parseInt(size) - row; i++) {
IO.print(" ");
}
for (int i = 0; i < row * 2 - 1; i += 2) {
IO.print("**");
}
IO.println();
}
// Second half of the circle
for (int row = 1; row <= Integer.parseInt(size); row++) {
for (int i = Integer.parseInt(size); i > Integer.parseInt(size) - row; i--) {
IO.print(" ");
}
for (int i = Integer.parseInt(size); i > row / 2 - 1; i -= 2) {
IO.print("**");
}
IO.println();
}
}
I'm not 100% sure I understand how the first half of the circle is working, what I am able to gather is that for each row I will create the required spaces and **s needed until I hit the size I've specified. So my thought was I can then replicate the first half and just mirror it (flip it) using the size I specified as the starting point for both the " "s and the **s. But the result I am seeing doesn't fully mimic what I was expecting.
How big do you want this circle? 5
**
****
******
********
**********
******
******
******
****
****