Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By DarrylBurke
  • 1 Post By Junky

Thread: Need observation of this code.

  1. #1
    nokick is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default Need observation of this code.

    Can anyone explain what this code about, by line?

    Java Code:
    public class JavaTwoDimensionArray{
    	
    /** Creates a new instance of JavaTwoDimensionArray */
    public JavaTwoDimensionArray(){
    	}
    	public static void main(String[] args){
    		
    	//Declare and create two dimensional int array whose size is
    	//10 by 5
    	int[][] ages = new int[10][5];
    	
    	//Display the number of rows and columns
    	System.out.println("ages.length = " + ages.length);
    	System.out.println("ages[1].length = " + ages[1].length);
    	
    	//Display the value of each entry in the array
    	for( int i=0; i<ages.length; i++){
    		System.out.println("\nStarting row " + i);
    		for( int j=0; j<ages[i].length; j++){
    		ages[i][j] = i * j;
    		System.out.print(ages [i][j] + "");
    		}
    		}
    		}
    	}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    -- redundant no-arg constructor
    -- really really bad formatting, read Code Conventions for the Java(TM) Programming Language: Contents
    -- do your own homework and you won't need someone to provide an explanation of borrowed code, go through The Java™ Tutorials
    -- heck, the largely redundant comments already explain what the code is supposed to do

    db
    Fubarable likes this.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Java Code:
    System.out.print(ages [i][j] + "");
    Arrrrgh!

    Kill the redundant code. Kill it now!
    DarrylBurke likes this.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by nokick View Post
    Can anyone explain what this code about, by line?
    Done! Now what do I win?

Similar Threads

  1. Replies: 3
    Last Post: 08-10-2011, 10:17 AM
  2. Replies: 0
    Last Post: 08-07-2011, 09:32 PM
  3. Replies: 0
    Last Post: 02-21-2011, 12:50 PM
  4. Replies: 1
    Last Post: 03-04-2010, 12:19 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •