Diamond with nested for loop in Java

前端 未结 7 612
暗喜
暗喜 2021-01-23 13:27

I am trying to display a diamond of asterisks using nested for loops.

Here is my code so far:

public          


        
7条回答
  •  一个人的身影
    2021-01-23 13:52

    int n = 9;
    for(int i =0;ii;k--){
            System.out.print(" ");
        }
        for(int j=0;j<2*i+1;j++){
            System.out.print("*");
        }
        System.out.println("");
    }
    
    for(int j=0;j=0;k--){
            System.out.print(" ");
        }
        
        for(int i=2*(n-j-1)-1;i>0;i--){
            System.out.print("*");
        }
        
        System.out.println("");
        
    }
    

提交回复
热议问题