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.
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]);
}
}
}