展开全部
三个for循环打印打印任意边长菱形
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入你要打印的空心菱形的边长:");
int s= sc.nextInt();
int a=s+1;
int b=s-1;
int c=2*b+a;
int d=s*2-1;
for (int i=1;i<=d;i++){
if (i<=b){
for (int j=1;j<=d;j++ ){
if (j==b+i||j==a-i){
System.out.print(" * ");
}else {
System.out.print(" ");
}
}
}else {
for (int k=1;k<=d;k++){
if (k==i-b||k==c-i){
System.out.print(" * ");
}else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
效果62616964757a686964616fe59b9ee7ad9431333431346435图:请输入你要打印的空心菱形的边长:5
*
* *
* *
* *
* *
* *
* *
* *
*
Process finished with exit code 0