Here is an array declaration containing income values for fi

Here is an array declaration containing income values for five years consecutively: int[] income = {1200, 1000, 1700, 1300, 2000}; int i; int howManyYears = income.length;//to display the 3^rd year income, in this statement System.out.print (3^rd year income\" + income[i]; What should be the value of index i? ANS (1) What is the value of variable: how Many Years? ANS (2) ANS: (1) index i = ANS (2): What is wrong with the following code to initialize an array BMI for every element to zero? To compile this code, will compiler generate any syntax error? If compilation is passed, what would happen when the byte code is executed? Explain in detail double[] BMI = new double[20]; for (int i = 1;

Solution

28) (1) 2, If we need access the 1st element we use 0, and to access the 3rd element we use 2.

(2)5, howManyYears will hold the length of the array which is 5 in this case.

29) (1) Yes

(2) The loop starts at i=1 and it keeps on going at one point i reaches 20 and as BMI.length is 20 so the statement i<=BMI.length is true so the loop is entered. But BMI[20] means illegal memory access, so it throws an exception and code throws an error.

 Here is an array declaration containing income values for five years consecutively: int[] income = {1200, 1000, 1700, 1300, 2000}; int i; int howManyYears = in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site