Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

2d array index out of bounds

807601Jan 3 2008 — edited Jan 4 2008
Hi, this has been reviewed many times I ques, but lets make it on more time :) I am a little confused working with a 2d array, I seem to have mised something how it calculate the length. I thought my code where correct but i get the famous out of bounds on index 5. I am stumbling in the dark, give me a hint, but not a working code please.

My code
public String addString (String in_array[] [], String in_name) {
		
	     //test
	    //length=in_array.length;
	
	    for (int row=0; row<in_array.length; row++) {
		for (int col=0; col<in_array[row].length; col++) {
		in_array[vertCount][hortCount]=in_name;
		
		//Increment position value
		vertCount++;
		hortCount++;
		
		//debug
		System.out.print(in_array[row] [col] +" ");
		}
        }
		
	    return in_name;
	
    }
Remember, no code, just a hint.

Martin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2008
Added on Jan 3 2008
6 comments
989 views