Computer problems,Computer help
*AX SOFT>>>Programming & Design

Can anyone help me about multidimensional java code here?


To create 2 multidimensional arrays size 3x3 use Math.random to get int value put in the arrays and but the value is between 1-9 after that add the two arrays get the result put in the new array and display all the arrays.

I already start some but when I compile it show ArrayIndexOutOfBoundsException: 3

int array1[][] = new int[3][3];
int array2[][] = new int[3][3];
int addarray[][] = null;

int i, j;

for(i =0; i < array1.length; i++) {
for( j =0; j < array1[i].length; j++)
array1[i][j] = (int) (Math.random() * 100);
array2[i][j] = (int) (Math.random() * 100);
}
for(i =0; i < array1.length; i++) {
for( j =0; j <array1[i].length; j++)
System.out.print(array1[i][j] + " ");
System.out.print(array2[i][j] + " ");

Anyone can help me ?

You're just missing the braces around the inner
"for" loops. As it is, the "j" loop iterates on the
assignment of "array1", then falls out to the
array2 assignment after "j" has been incremented
past the end of the array.

Once you put braces around *both* assignment
statements, the code works fine (I tested it).

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Photoshop to Illustrator cut-outs?

    Remove the background in Photoshop, then try saving it as a transparent PNG.

    ...
  • How does Myspace create it's pages to allow users to apply code changes, what languages and techniques?

    It's pretty easy to do. In fact, most sites do allow it if they aren't secured properly. If you use MySpace, you know that there are no designated places for style changes. (At least t...

  • I have problem with StreamToken that get data from keyboard at the same line at the time?

    Instead of StreamToken, how about leveraging BufferedReader along with Integer.parseInt(): public static void main(String[] args) throws Exception { int[] a = new int[10]; int counter = 0; i...

  • Is there a free program i can use to make a basic social network for my school?

    You could use the following: Ning - ...

  • Here's a riddle, and also a JCreator/Java Programing question.?

    Its the common multiple of all of them. The condition works for all students in that position. Ex. The 1st 5th student will have sunglasses. The 4th 5th student will also have sunglasses...

  • Creating a Gadge on Windows Vista.?

    You can make gadgets????????? Cool, I was wonderin why they had no good ones to download

    ...
  • Do i hav to jail break my ipod touch to get ibeer and all those other apps?

    Yeah You Have To Jailbreak It. Its Actually Really Simple. Theres A Website That Does It For You. And It Has Yet To Give Me A Viruis And It Has Some Cool Features. The iBeer thing though is a v...

  • Can any one recomend a free web hosting company that dont give you a website builder that sopport full HTML.?

    If you are serious about websites either for personal or your business, don't go to free web hosting as they are usually not reliable and you may end up losing all your hard work. Free web hos...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster