Problem in the Java Reverse a String Code Project
Hello, I want to solve the Reverse a String code Project but I am getting an exception that says "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 17 out of bounds for length 17 at Program.main(Program.java:13)" I looked up what the exception meant and Oracle said it means that "The index is either negative or greater than or equal to the size of the array," but I don't understand how I wrote the code to be greater than or equal to the size of the array. (Please see the code below.) Does anyone know why it's throwing this exception? Thanks, Iulia import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String text = scanner.nextLine(); char[] arr = text.toCharArray(); //int x = arr.length; for (int i = arr.length; i > 0; i--) { System.out.println(arr[i]); //arr--; } } }