Declare an array to hold 4 integers and fill it with the numbers 2, 4, 6, and 8.
ID: 3652856 • Letter: D
Question
Declare an array to hold 4 integers and fill it with the numbers 2, 4, 6, and 8. Assume an array called AR contains 4 integers. Write a loop to print out the values of the 4 integers. Assume an array called AR contains 4 integers. Write code to exchange the very first and the very last values in the array. Declare an array to hold 1000 integers. In the declaration statement, initialize the array so the very first value is 10, the second is 20, and all the rest are 0. Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _____ to ______. Complete the following sentence: the unsubscripted name of an array is _______________________________. Write code to swap element [2] and element [4] in an array of floats called AR. Declare a simple variable called temp for this question, and assume the array is correctly declared and initialized. Write code to copy the 0th element of an array called AR into all the other elements of the array. Assume there are 10 elements in the array. Complete the following sentence: all the elements of an array must be the same ____________. (True/False) ALL of the declared elements in an array MUST be initialized and used. Write a function called squareAr that squares the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be squared (N). The function returns nothing. Write a function called calcAvg that calculates and returns the average of the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be use in the calculation (N). The function returns a double: the calculated average. The function can assume N >= 0.Explanation / Answer
example Write a program that declares a double or String array of length 4, prints the values, assigns a value to each element, and prints the values again. int sum = 0; for (int i = 0; i < 10; i++) { sum += numbers[i]; } We start at 0 because indexes start at 0. We end just before 10 because 10 is the length of our numbers array, and the last index is one less than the length of the array. [Arrays provide many opportunities for off-by-one errors because of the way indexes work.] If we changed the numbers array to have a different number of elements, this code would no longer work. Fortunately, Java provides a easy way to obtain the length of an array, by appending .length after the array variable, for example: int sum = 0; for (int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.