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

thanks nothing to advanced as we just learned arrays 5. Create another Java clas

ID: 665876 • Letter: T

Question

thanks nothing to advanced as we just learned arrays

5. Create another Java class called LabQuestion5 within the same project Lab6. Write a Java program as follows. a. Declare integer 2D array with 5 rows and 5 columns. b. Initialize the array elements to random integers between I and 10. c. Perform the tasks given below. i. Display all the elements in the 2D array as a table of rows and columns. ii. Find the minimum of first row. iii. Find the maximum of third column. Use following statement to get the integer random numbers between 1 - 9. Int r= (int)(Math.random()*(9-1+1))+1;

Explanation / Answer

public class LabQuestion5 {
public static void findMinimum(int arr[][])
{
    int mini=20;
    for(int i=0;i<5;i++)
    {
      if(arr[0][i]<mini)
        mini=arr[0][i];
    }
    System.out.println ("The minimum of first row : "+mini);
}
public static void findMaximum(int arr[][])
{
    int maxi=0;
    for(int i=0;i<5;i++)
    {
      if(arr[i][2]>maxi)
        maxi=arr[0][i];
    }
    System.out.println("The maximum of third column : "+maxi);
}
public static void display(int arr[][])
{
    System.out.println("The double dimensional int array");
    for(int i=0;i<5;i++)
    {
      for(int j=0;j<5;j++)
      {
        System.out.print(arr[i][j]+" ");
      }
      System.out.println();
    }
}
public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int[][] arr=new int[5][5];
    for(int i=0;i<5;i++)
    {
      for(int j=0;j<5;j++)
      {
        int r=(int)(Math.random()*9) +1;
        arr[i][j]=r;
      }
    }
    display(arr);
    findMinimum(arr);
    findMaximum(arr);
}
}