java怎么打印空心菱形
发布网友
发布时间:2022-05-16 02:20
我来回答
共1个回答
热心网友
时间:2023-08-22 11:11
Scanner sn = new Scanner(System.in);
int shuRu = sn.nextInt();//7
for(int i =0;i < 2*shuRu-1;i++){//i 0 1
for(int j =0;j<Math.abs(shuRu-(i+1));j++){
System.out.print(" ");
}
for (int j1 = 0; j1 <shuRu*2-1-2*Math.abs(shuRu-(i+1)); j1++) {
if(j1==0||j1==shuRu*2-1-2*Math.abs(shuRu-(i+1))-1){
System.out.print("*");
}else {
System.out.print(" ");
}
}
System.out.println();
}