Answer the following questions concerning Arrays and write down the corresponding Java statements. Please type in the answers here and submit them on Canvas. Declare and instantiate an array called myExams to hold 4 exam scores. The exam scores will be floating-point numbers (double). After declaring array myExams, each element of the array has what value in it? Now, load the following exam scores into your existing array. 92.3 82.0 98.4 91.0 Display the 2nd component of myExams using System.out.println? What are you expecting to be displayed with the above statement? Display all of the components of your array using System.out.println in a for loop. Add up all of the exam scores in your array and store the total in a double variable called sum. This will be another for loop! Explain array bounds checking. What happens when an invalid index is used for an array? Display all of the components of your array using for each loop also called an enhanced for loop.

Respuesta :

Answer:

Check the explanation

Explanation:

(1)

class Brainlyarray{  

public static void main(String args[]){  

double myExams[]=new double[4]; //declaration & instantiation  

(2)

Each index of the array myExams have a garbage value stored on it's every index as at this point only the array is declared but not initialized the indexes are not holding any value yet.

(3)

myExams[0]=92.3; //initialization  

myExams[1]=82.0; //initialization

myExams[2]=98.4;  //initialization

myExams[3]=91.0;    //initialization

(4)

System.out.println(myExams[1]); // Will Print the 2nd component of the array

(5)

It will print the 2nd index of the 1D array myExams and the value which will be printed on the screen is 82.0

(6)

for(int i=0;i<myExams.length;i++) // length is the size of this 1D array and in this for loop this loop will run till the end of the length of the array which means till the size of the array.

System.out.println(myExams[i]);  

(7)

double sum=0.0; // Delaration of the sum variable

for(double num : myExams){ //For loop here num is the storage container where all the elements of the array myExams are been stored

sum=sum+num;

}

(8)

Array Bound Checking is basically the process in which it is being ensured that the value that is been entered is meeting the array boundaries or not as the array index value should be equal or greater than zero and less or equal to the size of the array.

and if we enter an invalid index value so it will be throwing an exception in thread of the main.

(9)

for ( double value : myExams){ //for each loop (Enhanced for loop )

System.out.println(myExams);

}

////////////////////////////////////////////////////////////////////////////////