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.
You might also like to view...
Why would you use an OR condition in a query?
What will be an ideal response?
An outline imported in a .txt format can be used to create a hierarchy in PowerPoint without having to retype the text. You simply move the text around to create the structure
Indicate whether the statement is true or false