The program will give the following output

55 45 36

28 21

15

10 6

3 1 0


Now, I have managed to print only the followings:

55 45 36

28 21 // This line with some kind of error though it ran.

Now what should be the addtional codes to get the afformentioned
diagram?

public class Task2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
            
        int     a = 55,
                
                differenttiator=10; 
             
        int [][] newArray=new int[5][];
            
        newArray[0]=new int[3];
        newArray[1]=new int[2];
        newArray[2]=new int[1];
        newArray[3]=new int[2];
        newArray[4]=new int[3];
        
        
        for(int row=0; row<5; row++){
            for(int col=0; col<3; col++){
            newArray[row][col]=a;
            System.out.print(" " +newArray[row][col]);
            a=a-differenttiator;
            differenttiator=differenttiator-1;
            }
            System.out.println("");
        }
        
        

    }
}

Recommended Answers

All 2 Replies

Asking Output is like

55 45 36
28 21
15
10 6
3 1 0

Don't loop like this:

for(int row=0; row<5; row++){
for(int col=0; col<3; col++){

Always like this:

for(int row=0; row<array.length; row++){
for(int col=0; col<array[row].length; col++){
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.