I'm trying to change the following code so I get this output for radius 2:
*****
*** ***
** **
*** ***
*****
Any help will be appreciated as I'm about to go crazy!
public class Main {
public static void main(String[] args) {
// dist represents distance to the center
double dist;
double radius = 2;
// for horizontal movement
for (int i = 0; i <= 2 * radius; i++) {
// for vertical movement
for (int j = 0; j <= 2 * radius; j++) {
dist = Math.sqrt(
(i - radius) * (i - radius) +
(j - radius) * (j - radius));
// dist should be in the range (radius - 0.5)
// and (radius + 0.5) to print stars(*)
if (dist > radius - 0.5 && dist < radius + 0.5)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println("");
}
}
}