Question

A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive

This is java, please follow my request and use netbeans. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.CODE->

public class Test {

   public static void main(String[] args) {
       int [][]arr = new int[3][3];
      
       System.out.println("Array is: ");
      
   int x = 1;
   for (int i = 0; i < 3; i++)
   {
   for (int j = 0; j < 3; j++)
   {
   arr[i][j] = x++;
   System.out.print(arr[i][j]+" ");
   }
   System.out.println();
   }
  
   System.out.println();
  
  
   System.out.println("total sum of array : "+getTotal(arr));
   System.out.println("average of array : "+getAverage(arr));
  
   int i=2;
   System.out.println("sum of : "+ i+"th row in the array : "+getRowTotal(arr,i));
   System.out.println("sum of : "+ i+"th column in the array : "+getColumnTotal(arr,i));
  
   int m=1;
   System.out.println("Maximum in the "+m+"th row : "+getHighestInRow(arr,m));
   System.out.println("Minimum in the "+m+"th row : "+getLowestInRow(arr,m));

   }
  
   public static int getTotal(int[][] arr)
   {
       int sum=0;
       for(int i=0;i<arr.length;i++)
       {
           for(int j=0;j<arr[i].length;j++)
           {
               sum+=arr[i][j];
           }
       }
      
       return sum;
   }
  
   public static double getAverage(int[][] arr)
   {
       int m=arr.length;
       int n=arr[0].length;
       double ans=(1.0 * getTotal(arr))/(m*n);
       return ans;
   }
  
   public static int getRowTotal(int[][] arr,int i)
   {
       int sum=0;
       if(i>=arr.length)
           return sum;
      
      
       for(int j=0;j<arr[i].length;j++)
           sum+=arr[i][j];
       return sum;
          
   }
  
   public static int getColumnTotal(int[][] arr,int j)
   {
       int sum=0;
       if(j>=arr[j].length)
           return sum;
      
      
       for(int i=0;i<arr.length;i++)
           sum+=arr[i][j];
       return sum;
          
   }
  
   public static int getHighestInRow(int[][] arr,int i)
   {
       int max=arr[i][0];
       for(int j=0;j<arr[i].length;j++)
       {
           if(arr[i][j]>max)
               max=arr[i][j];
       }
      
       return max;
      
   }
  
  
   public static int getLowestInRow(int[][] arr,int i)
   {
       int min=arr[i][0];
       for(int j=0;j<arr[i].length;j++)
       {
           if(arr[i][j]<min)
               min=arr[i][j];
       }
      
       return min;
      
   }
  

}

2.OUTPUT->

| 3 | BE R = = = = = = = & Console X Task List <terminated Test [Java Application] C:\Program Files Vava\jdk-12.0.1\bin\javaw

I DID THIS IN ECLIPSE BECAUSE I DONT HAVE NET BEANS RIGHT NOW BUT I THINK IT WILL HELP YOU IN GETTING THE LOGIC. I WILL BE GLAD IF IT HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates...

    Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates a two-dimensional 2 rows by 3 columns double array. This class will have a separate method for the user to populate the array with data values. The other class that has the following methods:   getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.   getAverage. This method should accept a two-dimensional array...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

  • Please solve only if you know how to do it. Write the code using C++ (not...

    Please solve only if you know how to do it. Write the code using C++ (not Python or Java). Show and explain everything neatly. COMMENTS (7.5% of programming assignment grade): Your program should have at least ten (10) different detailed comments explaining the different parts of your program. Each individual comment should be, at a minimum, a sentence explaining a particular part of your code. You should make each comment as detailed as necessary to fully explain your code. You...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Please solve this C language progrm (2-D Array program) the most basic way ! Thank You!...

    Please solve this C language progrm (2-D Array program) the most basic way ! Thank You! Write a function that takes a 4 x 4 array of integers as its parameter. The function must use two nested for-loops to determine the largest integer in the array as well as its row and column numbers. Recall that C-functions cannot return multiple values. Use pointers in the function parameter list to relay the results to the caller program. Write another function, which...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer...

    Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2-Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class...

  • Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’,...

    Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’, the goal is to assign digits (from 1 to 9) to the empty cells so that every row, column, and subgrid of size 3×3 contains exactly one instance of the digits from 1 to 9. I have posted 3 input files: sudoku1.txt, sudoku2.txt and sudoku3.txt Problem Analysis & Design - Think about how you will need to solve this problem. You should do an...

  • please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement...

    please do all in C++ code, thank you. Worth 1 point Checkpoint 7.12 Write a statement that assigns the value 10 to the first elementof an array of integers named minutes. Type your program submission here Worth 1 point Checkpoint 7.14 Write a cout statement that will display contents of the second element of an array named courseNumbers Type your program submission here Submit Worth 1 point Checkpoint 7.15 Write a cin statement that will store the user's input in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT