用JAVA实现的,用星号打一个菱形
展开全部
public class Test {
public static void print(int n){
int index1 = n/2;
int index2 = index1;
for (int i = 0; i < n; i++){
for (int j = 0; j < 2 * n - 1; j++){
if (j == index1 || j == index2){
System.out.print("*");
} else{
System.out.print(" ");
}
}
if ( i >= n / 2){
index1 += 2;
index2 -= 2;
} else{
index1 -= 2;
index2 += 2;
}
System.out.println();
}
}
public static void main(String args[]){
print(9);
}
}
public static void print(int n){
int index1 = n/2;
int index2 = index1;
for (int i = 0; i < n; i++){
for (int j = 0; j < 2 * n - 1; j++){
if (j == index1 || j == index2){
System.out.print("*");
} else{
System.out.print(" ");
}
}
if ( i >= n / 2){
index1 += 2;
index2 -= 2;
} else{
index1 -= 2;
index2 += 2;
}
System.out.println();
}
}
public static void main(String args[]){
print(9);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询