public class test {
public static void main(String[] args) {
int n = 7;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(j == i || j == n-1-i){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
n为宽度
菱形图案
public class test {
public static void main(String[] args) {
int n = 7;
int k = 0;
boolean falg = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == n / 2 + k || j == n / 2 - k) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
if (k == -3) {
falg = true;
}
if (falg) {
k++;
} else {
k--;
}
System.out.println();
}
}
}