java怎么打印空心菱形
1个回答
展开全部
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();
}
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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询