急求利用java的循环输出数字三角形,具体如下。最好用4种for循环输出 !

1
121
12321
1234321
123454321
1
121
12321
1234321
123454321
错了 数字图形是这个 1是在2正上方的


纯粹的for循环,望采纳!

int count = 0;

Scanner sc = new Scanner(System.in);

System.out.println("输入层数:");

count = sc.nextInt();

for(int i=1;i<=count;i++){

for(int k=count;k>i;k--){

System.out.print(" ");

}

if(i==1){

System.out.println(i);

}else{

for(int j=i;j<=i;j++){

for(int m =0;m<=j;m++){

if(m==0){

System.out.print("1");

}else if(m<j){

System.out.print(m+1);

if(m==j-1){

//饱和 ,反过来

//123现在就要21

for(int f=m;f>1;f--){

System.out.print(f);

}

}

}else if(m==j){

System.out.print("1");

System.out.println("");

}

}

}

}

}



4个for:

public static void main(String[] args) {

int count = 0;

Scanner sc = new Scanner(System.in);

System.out.println("输入层数:");

count = sc.nextInt();

for(int i=1;i<=count;i++){

Recycling(count,i,1);

if(i==1){

System.out.println(i);

}else{

for(int j=i;j<=i;j++){

for(int m =0;m<=j;m++){

if(m==0){

System.out.print("1");

}else if(m<j){

System.out.print(m+1);

if(m==j-1){

//饱和 ,反过来

//123现在就要21

Recycling(m,1,-1);

}

}else if(m==j){

System.out.print("1");

System.out.println("");

}

}

}

}

}

}

/**

 * 

 * @param num1 

 * @param num2

 * @param bool 标志

 */

private static void Recycling(int num1, int num2,int bool) {

for (int f = num1; f > num2; f--) {

if(bool==-1){

System.out.print(f);

}else{

System.out.print(" ");

}

}

}

温馨提示:答案为网友推荐,仅供参考