My professor asked me to do the following homework in Java, but I'm getting error while trying to execute the code.
Please take a look at the code and let me know what's causing the error? The code is saved into Reverse.java file.
package javaapplication44;
import java.util.Scanner;
public class Reverse {
public static void main (String[] args) {
String Fname[] = new String[4];
Scanner s = new Scanner(System.in);
for (int i=0; i<=4; i++) {
System.out.println("\n Enter Something: ");
Fname[i] = s.nextLine();
}
System.out.println ("*** The String has been Reversed ***");
for (int i=4; i>0; i--) {
System.out.println (Fname[i]);
}
}
}
error text:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4 at javaapplication44.Reverse.main(Reverse.java:14)