Ok but how do I Initialize each cell with increasing integer number starting
from 1000, 1001, 1002, and so on?
Currently I get this -
The 3 represents the rows. - So rows 0 - 3 I understand that part.
The 6 represents the length -
The 9 represents the height -
Right now my output shows 3 rows which is correct. The rest I'm lost.
What should the correct output look like?
ages.length = 3
ages[1].length = 6
ages[2].length = 9
Starting row0
000000000000000000000000000000000000
Starting row1
0000000123450246810036912150481216200510152025
Starting row2
00000002468100481216200612182430081624324001020304050BUILD SUCCESSFUL (total
time: 2 seconds)
public static void main(String[] args) {
//Declare and create three dimensional int
//array whose size is 3 by 6 by 9
int[][][]ages = new int[3][6][9];
//Display the number of rows and columns
System.out.println("ages.length = " + ages.length);
System.out.println("ages[1].length = " + ages[1].length);
System.out.println("ages[2].length = " + ages[1][2].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++){
for ( int k=0; k<ages[i].length; k++){
ages[i][j][k]= i*j*k;
System.out.print( ages[i][j][k]+"");
}
}
}
}
}
From: [email protected]
[mailto:[email protected]] On Behalf Of Donald
Mellen
Sent: Sunday, July 12, 2009 3:57 PM
To: [email protected]
Subject: [java programming] Re: Exercise 1: Build and run Java programs that
use Java array of int
Think of your declaration:
int[][][]nums = new int[3][6][9];
as specifying a 3x6x9 rectangular box
the box would be 3 units wide, 6 units long and 9 units high.
nums.length is the width of the box.
nums[0].length is the length at the first width position.
nums[1].length is the length at the second width position
nums[2].length is the length at the third width position
since this is a uniform box, the length at any position is 6
If you want the height of the box at a particular point, you would need to
specify both a width and length location.
for example:
nums[1][2].length
This should give you the desired value.
Don Mellen
_____
From: Shawn Sampson <[email protected]>
To: Free Java Programming Online Training Course By Sang Shin
<[email protected]>
Sent: Sunday, July 12, 2009 6:07:08 PM
Subject: [java programming] Exercise 1: Build and run Java programs that use
Java array of int
Build and run a Java program that uses two-dimensional array of int
4. (For your own exercise) Create a NetBeans project as following.
Build and run the program.
Declare and initialize 3-dimensional array of int
Initialize each cell with increasing integer number starting from
1000, 1001, 1002, and so on.
----------------------------------------------------------------------------
--------------------------------
package threedarray;
/**
*
* @author wagle
*/
public class ThreeDArray {
public ThreeDArray (){
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Declare and create three dimensional int
//array whose size is 3 by 6 by 9
int[][][]nums = new int[3][6][9];
//Display the number of rows and columns
System.out.println("nums.length = " + nums.length);
System.out.println("nums[1].length = " + nums[1].length);
System.out.println("nums[2].length = " + nums[2].length);
}
}
----------------------------------------------------------------------
output:
run:
nums.length = 3
nums[1].length = 6
nums[2].length = 6
BUILD SUCCESSFUL (total time: 0 seconds)
--------------why is this "not" printing the following.
---------------
nums.length = 3
nums.length = 6
nums.length = 9
is there something I am missing?
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---