Java program In main method: Create 2-D Array, called m: the row size of array m is 15 ask user to input column size of array m fill all array elements as double numbers in the range of (7.0, 17.0) by using random object create 2-d array, called double [][]md = {{1,1,1},{2,0,1},{4,7,4}}; pass the above array m and md to call the following two methods MaxCol(m); MaxCol(md); System.out.println (“the average of array m is: ” + returnLast3RowAvg(m)); System.out.println (“the average of array md is: ” + returnLast3RowAvg(md)); Print out the largest column sum, and the average of the last 3 rows of array m and md. In MaxCol(double[][]array) method, find and print the largest column sum in the array. In returnLast3RowAvg(double[][]array) method, find the average of the elements in the last 3 rows in the array and return this average value.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java program

In main method:

  • Create 2-D Array, called m:
    • the row size of array m is 15
    • ask user to input column size of array m
    • fill all array elements as double numbers in the range of (7.0, 17.0) by using random object
  • create 2-d array, called double [][]md = {{1,1,1},{2,0,1},{4,7,4}};
  • pass the above array m and md to call the following two methods
    • MaxCol(m);
    • MaxCol(md);
    • System.out.println (“the average of array m is: ” + returnLast3RowAvg(m));
    • System.out.println (“the average of array md is: ” + returnLast3RowAvg(md));
  • Print out the largest column sum, and the average of the last 3 rows of array m and md.

In MaxCol(double[][]array) method, find and print the largest column sum in the array.

In returnLast3RowAvg(double[][]array) method, find the average of the elements in the last 3 rows in the array and return this average value.

Expert Solution
Step 1) Code is Given Below

import java.util.Scanner;

public class MyArrayTest {
 public static void main(String[] args) {
  //declaring 2D array
  double m[][]=new double[15][];
  Scanner sc=new Scanner(System.in);
  //asking user for input
  System.out.print("Enter Column size of array : ");
  int n=sc.nextInt();
  //populate m array by random values
  for(int i=0;i<15;i++) {
   m[i]=new double[n];
   for(int j=0;j<n;j++) {
    m[i][j]=(Math.random() * ((17.0 - 7.0) + 1)) + 7.0;
   }
  }
  //create 2D array
  double [][]md={{1,1,1},{2,0,1},{4,7,4}};
  //calling methods and print result
  MaxCol(m);
  MaxCol(md);
  System.out.println("Average of Last three Row element Array m : "+returnLast3RowAvg(m));
  System.out.println("Average of Last three Row element Array md : "+returnLast3RowAvg(md));
  
 }
 public static void MaxCol(double [][]array) {
  //creating variable to hold max value
  double max=0;
  //iterating from column by row order
  for(int j=0;j<array[0].length;j++) {
   double sum=0;
   for(int i=0;i<array.length;i++)
    //find sum
    sum=sum+array[i][j];
   //check for sum is greater than max
   if(max<sum)
    max=sum;
  }
  //print result
  System.out.println("Largest Column sum is : "+max);
 }
 
 public static double returnLast3RowAvg(double[][]array) {
  //creating variable to hold sum value
  double sum=0;
  int k=0;
  //this loop will run for three rows only
  for(int i=array.length-3;i<array.length;i++) {
   for(int j=0;j<array[i].length;j++) {
    //find sum
    sum=sum+array[i][j];
    k++;
   }
  }
  //return average
  return sum/k;
 }

}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education