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();
}
}
哪个大佬给我解释一下?
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();
}
}
哪个大佬给我解释一下?