展开全部
纯粹的for循环,望采纳!
int count = 0;
Scanner sc = new Scanner(System.in);
System.out.println("输入层数e69da5e887aa3231313335323631343130323136353331333330353538:");
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
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
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(" ");
}
}
}