import java.util.* ; public class Averager {     public static void main(String[] args)     {     //a two dimensional array     int[][] a = {{5, 9, 3, 2, 14}, {77, 44, 22, 15, 99},                  {14, 2, 3, 9, 5}, {88, 15, 17, 121, 33}} ;     System.out.printf("Average = %.2f\n", average(a)) ;     System.out.println("EXPECTED:") ;     System.out.println("Average = 29.85") ;     System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ;     System.out.println("EXPECTED:") ;     System.out.println("Average of evens = 26.57") ;     Random random = new Random(1) ;     a = new int[100][1] ;     for (int i = 0 ; i < 100 ; i++)         a[i][0] = random.nextInt(1000) ;     System.out.println("For an array of random values in range 0 to 999:") ;     System.out.printf("Average = %.2f\n", average(a)) ;     System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ;     }     /**        Find the average of all elements of a two-dimensional array        @param aa the two dimensional array        @return the average as a double      */     public static double average(int[][] aa)     {         //-----------Start below here. To do: approximate lines of code = 5         // 1. set total to zero ; Hint: use a double          double total = 0;         //2. make a nested loop to visit each element ;          int totallength=0;         for (int i=0;i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
import java.util.* ;

public class Averager
{
    public static void main(String[] args)
    {
    //a two dimensional array
    int[][] a = {{5, 9, 3, 2, 14}, {77, 44, 22, 15, 99},
                 {14, 2, 3, 9, 5}, {88, 15, 17, 121, 33}} ;
    System.out.printf("Average = %.2f\n", average(a)) ;
    System.out.println("EXPECTED:") ;
    System.out.println("Average = 29.85") ;
    System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ;
    System.out.println("EXPECTED:") ;
    System.out.println("Average of evens = 26.57") ;
    Random random = new Random(1) ;
    a = new int[100][1] ;
    for (int i = 0 ; i < 100 ; i++)
        a[i][0] = random.nextInt(1000) ;
    System.out.println("For an array of random values in range 0 to 999:") ;
    System.out.printf("Average = %.2f\n", average(a)) ;
    System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ;
    }
    /**
       Find the average of all elements of a two-dimensional array
       @param aa the two dimensional array
       @return the average as a double
     */
    public static double average(int[][] aa)
    {
        //-----------Start below here. To do: approximate lines of code = 5
        // 1. set total to zero ; Hint: use a double 
        double total = 0;
        //2. make a nested loop to visit each element ; 
        int totallength=0;
        for (int i=0;i<aa.length;i++){
            for (int j=0; j<aa[i].length;j++){
                total+=aa[i][j];
                totallength++;
            }
        }
        
        //3. increase total with each element ; 
        
        
        
       //4. return the average
        return total/(totallength);
        //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
    }
    /**
       Find the average of the even elements of a two-dimensional array
       @param aa the two dimensional array
       @return the average as a double
     */
    public static double averageEvens(int[][] aa)
    {
        //-----------Start below here. To do: approximate lines of code = 8
        // fill in the method
        
        
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY