ite a statement to allocate array storage for 15 values, to be accessed using th
ID: 3824590 • Letter: I
Question
ite a statement to allocate array storage for 15 values, to be accessed using the variable declared above rite a single statement that does the work of both parts (a) and (b) new DIS1 d) write a statement to print (display) the last element of the array to the standard output. (out pri temps tay, The lost elemed in i "der e) Write a program fragment to calculate the maximum value in the array and display it. Assume that the array has the values stored beforehand. This requires a loop. You may use any looping construct including a foreach loop. tents to] if (temps tinde) Mov) tinder] ll end loop od println (max), 2. Show the output from the following program fragment. int [1 arr 137 28 19, 110, 26 for (int k 0; k 5: k++) 26, ilo, 19, ilo, b arr[k] arr kla print Array (arr) 3. Show the output from the following program fragment int arr 134 27, 31 55, 12 Output 24, 3 SS, 12,12 for (int k 1: k 41 k++) arr [k] arr [k 11: printArray (arr); 2017-04-20 Form A Page 1 of 65Explanation / Answer
Please find the answers below.
1. a. int[] temp;
b. new int[15];
c. int[] temp = new int[15];
d. System.out.println(temp[14]);
e. Let us assume the maximum element is first element of the array.
int max = temp[0];
for(int i=1; i < temp.size(); i++){
if(max < temp[i]){
max = temp[i];
}
}
System.out.println("The max. element in the array is" + max);
2. The output is 26, 110 , 19, 28, 37
3. The output is 34, 31 ,55, 12
5. public static boolean hasNoEven(int[] arr){
boolean flag = true;
for(int i=0;i<arr.length();i++){
if(arr[i] % 2 ==0){
flag = false;
break;
}
}
return flag;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.