I am trying to write a program that display's the user's input in reverse. I know that there are better ways to do this but let me make a long story short by saying my teacher is not the most understanding of individuals that being said here's what I got so far:
public static void main(String[] args)
{
String input;
int len;
input = JOptionPane.showInputDialog(null, "Please enter a string value: ");
len = input.length();
char[] txt = new char[len];
for (int i = 0; i <= len; i++)
{
txt[i] = input.charAt(i);
}
for (int j = len; j >= 0; j--)
{
System.out.print(txt[j]);
}
}
The error I keep receiving is as follows:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at program.main(program.java:28)
It points to the line:
System.out.print(txt[j]);
I understand that the error is saying that I have exceeded the limits of the array I'm just not seeing how. Any help or input will be greatly appreciated. Thank You.