How to clear ArrayIndexOutOfBound
exception in java
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10 at word.main(word.java:17)
My code as follows:
import java.util.*;
import java.lang.*;
class word{
public static void main(String[] args){
String n;
String a[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};
String b[]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
System.out.println("Enter number in words");
Scanner sc=new Scanner(System.in);
n=sc.next();
for(int i=0;i<=20;i++){
if(n==a[i]){
System.out.println(i);
break;
}
else if(n==b[i]){
System.out.println(i);
break;
}
}
}
}