java编菱形图案程序,图案如下:******* ***** *** * *** ***** *******

2024-12-03 14:29:24
推荐回答(2个)
回答1:

private static void printSpace(int n){
for(int i=0;i System.out.print(" ");
}
}
private static void printStar(int n){
n=n*2-1;
for(int i=0;i System.out.print("*");
}
}
public static void printTriangle(int n,String directiorn){
if("up".equals(directiorn)){
for( int i=1;i<=n;i++ ){
printSpace(n-i);
printStar(i);
System.out.println("");
}
}else{
for( int i=n;i>=1;i-- ){
printSpace(n-i);
printStar(i);
System.out.println("");
}
}
}
public static void printRhombus(int n){
printTriangle(n,"up");
printTriangle(n,"down");
}
public static void main(String[] args){
printRhombus(5);
}

回答2:

是这样么?
*
***
******
***
*