#Challenge 7 - Loops Modern Jaa

1 messages · Page 1 of 1 (latest)

honest patio
#

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
    **
   ****
  ******
 ********
**********
 ******
  ******
   ******
    ****
     ****
boreal treeBOT
#

<@&987246399047479336> please have a look, thanks.

dusty quail
honest patio
dusty quail
#

ah

#

@limpid fox that's not a circle -_-

dusty quail
dusty quail
honest patio
# dusty quail I don't think you reversed the conditions correctly other side of > isn't < but ...

Ah I see where I went wrong, thank you

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();
    }

    for (int row = Integer.parseInt(size); row > 0; row--) {
        for (int i = Integer.parseInt(size) - row; i > 0; i--) {
            IO.print(" ");
        }

        for (int i = row * 2 - 1; i >= 0; i -= 2) {
            IO.print("**");
        }

        IO.println();
    }
}