Hello, I have this code:
import java.util.Scanner;
public class Question1 {
// public static char isConsecutive() {
//}
public static void main (String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter something: ");
String word=reader.next();
// creating an array
String[] ArrayKespass= word.split("");
System.out.println();
//place our letters in array, and print them
for (int x=0; x<ArrayKespass.length; x++) {
System.out.print(ArrayKespass[x] + " ");
}
// skip a line
System.out.println();
// convert our letters into characters
for (int i=0; i<=ArrayKespass.length; i++) {
char c=word.charAt(i);
}
}
}
It works, but when i execute it it gives me this in red:
java.lang.StringIndexOutOfBoundsException: String index out of range: 13
at java.lang.String.charAt(Unknown Source)
at Question1.main(Question1.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.ru nCommand(JavacCompiler.java:272)
Can someone please explain to me why? And what should I do to solve the problem?