I think there is a better way ...
public class ex3 {
public static void main(String[] args) {
int i, j;
int max = 5;
int p = max / 2 + 1;
int left = p;
int right = p;
for (i = 1; i <= max; i++) {
for (j = 1; j <= max; j++) {
if (j >= left && j <= right) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
if (i < p) {
left--;
right++;
} else {
left++;
right--;
}
}
}
}
Recommended Posts