Write Java statements that does the following: a. Defines a constant DIM equal t
ID: 3614637 • Letter: W
Question
Write Java statements that does the following:
a. Defines a constant DIM equal to 100.
b. Defines the arrayresult of size DIM and of typedouble.
c. Assign the value 99.99 to the first elementof result
d. Using a loop statement, set the rest of thearray elements in the result array so that theymatch their subscript value.
e. Using a loop statement, display the valuesof the last five elements of the array result.Answer the following questions:
f. Is the value 88.5 a legal element value forthe array result? Explain. g. Isthe value 88.5 a legal subscript value for the arrayresult? Explain.
Explanation / Answer
a. Defines a constant DIM equal to100. finalint DIM=100;
b. Defines the arrayresult of size DIM and of typedouble. double[] result=newDouble[DIM];
c. Assign the value 99.99 to the first elementof result result[0]=99.99;
d. Using a loop statement, set the rest of thearray elements in the result array so that theymatch their subscript value.
e. Using a loop statement, display the valuesof the last five elements of the array result.Answer the following questions:
for(inti=DIM-5;i<DIM;i++)
System.out.print(result[i]);
System.out.println();
f. Is the value 88.5 a legal element value forthe array result? Explain. yes, since the array is double itcontains values of real numbers which 88.5is
g. Is the value 88.5 a legal subscript valuefor the array result? Explain. no a subscript is the element index, itmust be an integer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.