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

Simple Java Array Out of Bounds Execption Problem

$
0
0
Hello

Could someone please tell me why my code is throwing an out of bounds exception -1 please?

Write a program that uses an array to store the names of five students. Your
program should then print out the names of the students in reverse order.

public class Q2
{
	public static void main (String [] args)
	{
		//Scanner kb = new Scanner(System.in);
		
		String [] arrayNames = {"Matthew", "Mark", "Luke" , "John" , "Joe"};
		
		for (int i = 4; i < arrayNames.length; i--)
		{
			System.out.println (arrayNames[i]);
		}		
	}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



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