java吧 关注:1,240,917贴子:12,714,719
  • 0回复贴,共1

打印任意空心菱形,这个代码我怎么看不懂

只看楼主收藏回复

import java.util.*;
public class diamonds
{
public static void main(String[] args)
{
System.out.print("please input diamonds r: ");
Scanner sc = new Scanner(System.in);
int r =sc.nextInt();
for(int y=0;y<=2*r;y++){
for(int x=0;x<=2*r;x++){
if(y==-x+r||y==x-r||y==-x+3*r||y==x+r){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
哪个大佬给我解释一下?


IP属地:辽宁1楼2021-05-06 20:59回复