Java Write Program Contains Bounds Error Run Program Happens Computer Q37175471

in java Write a program that contains a bounds error. Run theprogram. What happens on your computer?


Answer


Error output will be:

Main.java 1 public class Main public static void main (String args int array] 1, 2, 3; 6 out.println(array[i]); System 8 inpu

Code is shown below:

public class Main
{
public static void main(String[] args)
{
int array[] = {1, 2, 3};
for (int i=0; i<=array.length; i++)
System.out.println(array[i]);
}
}

Note:

This error cannot be find at the compilation time.

It can be hit only after the execution.

An exception will be thrown to the computer screen intimatingthe user about the out of bounds of an array occurred.

Here 0,1,2 position

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.