3个回答
展开全部
按照你的要求编写的Java程序如下:
import java.util.Scanner;
public class Test8 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个正奇数:");
final int N=sc.nextInt();
for(int m=1;m<=2*N;m+=2){
for (int i = 1; i <=2*N; i+=2) {
for(int k=1;k<=Math.abs(N-m);k+=2){
for (int j = 1; j <= Math.abs(N-i); j+=2) {
System.out.print(" ");
}
for (int j = 1; j <=N- Math.abs(i-N); j++) {
System.out.print(" ");
}
for (int j = 1; j <= Math.abs(N-i); j+=2) {
System.out.print(" ");
}
}
for(int k=1;k<=N- Math.abs(m-N);k++){
for (int j = 1; j <= Math.abs(N-i); j+=2) {
System.out.print(" ");
}
for (int j = 1; j <=N- Math.abs(i-N); j++) {
System.out.print("*");
}
for (int j = 1; j <= Math.abs(N-i); j+=2) {
System.out.print(" ");
}
}
System.out.println();
}
}
}
}
运行结果:
请输入一个正奇数:
3
*
***
*
* * *
*********
* * *
*
***
*
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询