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.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
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 {
a[10]=20;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("index is wrong");
}*/
a[10]=20;System.out.println(a[10]);
}
}
#java
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
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
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
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.
...