Printint 2-d Array

Discussion in 'Java' started by cyrow, Apr 18, 2008.

  1. cyrow

    cyrow New Member

    Joined:
    Nov 19, 2007
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    import java.io.*;
    import java.util.*;
    
    
    //Print all the elements below the leading diagonal as zeros(The leading diagnol is where all the row index equal the column index.
    
    class Printsqu{
    	public static void main(String[] args){
    	int [][]array = {
    					
    					{1,1,1,1},
    					{1,1,1,1},
    					{1,1,1,1},
    					{1,1,1,1},
    	};
    	
    			for(int i = 0; i < array.length; i++){
    				for(int j = 0 ; j <array[i].length; j++){		
    					System.out.print(array[i][j]);
    				
    			}
    			System.out.println();
    		}		
    	}//main
    }//end method
    
    Problem
    I am trying to print the 4x4 array above with the digits below the diagnol (intersection of the rows and cols) zero. I am having some problems with the logic. When I write the data out I can see certain things, but when I code it, it just does not work? Any ideas?
    ________________________________________
     
    Last edited by a moderator: Apr 18, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice