20160722

Array Index Out Of Bounds

class ArrayIndexOutOfBounds {
   
  public static void main(String[] args) {
 
    String languages[] = { "C", "C++", "Java", "Perl", "Python" };
 
    try {
       
      for (int c = 1; c <= 5; c++) {
         
        System.out.println(languages[c]);
         
      }
       
    } catch (Exception e) {
       
      System.out.println(e);
       
    }
  }
}

OUTPUT

C++
Java
Perl
Python
java.lang.ArrayIndexOutOfBoundsException: 5

Disqus Shortname

Recent Post Number

Related Post Number

Comments system