Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Getting an array index out of bounds exception error at run.

$
0
0
As title says im getting an index out of bounds exception error at runtime.

Here is the code.
public class Assign7
{
	public static void main(String[] args)
	{
		int [][] intar = { {10, 12, 13, 14 },
						   {15, 16, 17, 18 },
						   {19, 20, 21, 22 } };
		System.out.println("Here are the values in the array.");
		showArray(intar);
	}

	private static void showArray(int[][] intar)
	{
		for (int row = 0; row<3; row++)
		{
			for (int col = 0; col<4; col++)
			   System.out.print(intar[col][row]);

		}
  	}
}



By the way the output of the program should be 10,15,19,12,16,20,13,17,21,14,18,22.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>