public class CostArray
{
    public static void main(String[] args)
    {
       double[] costs = new double[3];
       costs[0] = 5.00;
       costs[1] = 7.00;
       costs[2] = 9.00;
       System.out.println(costs[3]);
    }
}
?
Once the above code is compiled and executed, an error message is generated. Explain the error message that will result and explain the reason for the error.

What will be an ideal response?


An out-of-bounds error is generated when the code is compiled and executed. The last executable line in the code is an output statement that attempts to display a costs value using a subscript that is beyond the range of the array: System.out.println(costs[3]). The program will run successfully when the subscript used with the array is 0, 1, or 2. However, when the subscript reaches 3, the ArrayIndexOutOfBoundsException error is generated. The message indicates that the subscript is out of bounds and that the offending index is 3.

Computer Science & Information Technology

You might also like to view...

A(n) _________________________ layer is a new layer added to an image to affect a tonal change to a large portion of the image.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Answer the following statement(s) true (T) or false (F)

Of the three methods of access control (RBAC, DAC, and MAC), RBAC is the least secure of the options.

Computer Science & Information Technology

The paragraph mark (¶) as shown in the accompanying figure is a formatting mark that indicates where the _____ was pressed.

A. TAB key B. SPACEBAR C. ENTER key D. SHIFT key

Computer Science & Information Technology

When ____ is selected in the Word Options dialog box, the options available affect the spelling and grammar checker.

A. Proofing B. Editing C. Spelling and Grammar checking D. Words

Computer Science & Information Technology