Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

iam assigning the value of a[10]is 20 but the output is ArrayIndexOutOfBoundsException

+3 votes
asked Nov 30, 2022 by Gopi Krishna (400 points)
class Main
    public static void main(String[] args)
        int a[]=new int[10];
      /*  try {
        catch(ArrayIndexOutOfBoundsException e)
            System.out.println("index is wrong");

1 Answer

+5 votes
answered Nov 30, 2022 by Srivathsa (240 points)
in this array the max index is 9 as we know that initialization starts from 0 so
0 1 2 3 4 5 6 7 8 9 ==>  the array size is 10 and there is no index 10 so comes the error
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.