I am trying to access an array of characters by reading the array index from a String.
public class HelloWorld {
public static void main(String[] args) {
// 0123456789
char[] code = {'A', 'B','C','D','E','F','G','H','I','J'};
String orig = "0123456789";
for ( int i=0; i <10; i++) {
System.out.print(code[orig.charAt(i)]);
}
}
}
I was hoping for the output of ABCDEFGHIJ but instead I get a runtime error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 48
at HelloWorld.main(HelloWorld.java:9)