Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions : Complete the following questions, for most of the questions the ret

ID: 3712636 • Letter: D

Question

Directions: Complete the following questions, for most of the questions the return type and name of the method are left out. Give each method a meaningful name and appropriate return type.

Make a method that prints out the middle row of a 2D integer array. Separate each element with a space. If there is no middle row, then print out, “There is no middle row!”.

Make a method that accepts a 2D array of Strings and returns true if the array has the word “banana”.

Write a method that accepts a 2D array of integers and returns the sum of the entries in the bottom-left to top-right diagonal of a two-dimensional array of integers. For this method, assume the array is square.

Explanation / Answer

Doing first one as per chegg policy

Make a method that prints out the middle row of a 2D integer array. Separate each element with a space. If there is no middle row, then print out, “There is no middle row!

void printMiddle(int[][] arr) {
if (arr == null || arr.length <= 3 || (arr.length % 2 == 0)) {
System.out.println("There is no middle row!");
}
int mid = arr.length/2;
for(int j = 0; j < arr[mid].length; j++) {
System.out.print(arr[mid][j] + " ");
}
System.out.println();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote