Question

Programming Assignment #2 CMPS 280 Problem Description: Write a method that returns the smallest element in...

Programming Assignment #2 CMPS 280 Problem Description: Write a method that returns the smallest element in a specified column in a matrix using the following header: public static double columnMin(double[][] m, int columnIndex) Write a program that reads from the keyboard the number of rows and columns, and an array of double floating point numbers with the specified number of rows and columns. The program will then invoke the columnMin method and displays the minimum value of all columns. Run and make sure that your program produces exactly the same output for each of the sample inputs listed below.

Sample Input 1:

5

4

6.7 12. 2.0 3.9

14. 4.1 4.9 12.

16. 8.9 10. 2.0

3.2 18. 19. 14.

6.7 7.6 13. 7.4

Sample Output 1:

3.2 4.1 2.0 2.0

Sample Input 2:

3

7

14. 4.5 20. 9.3 17. 4.0 6.3

7.6 20. 7.5 15. 19. 11. 9.9

4.4 2.4 16. 11. 13. 16. 14.

Sample Output 2:

4.4 2.4 7.5 9.3 13.0 4.0 6.3

Sample Input 3:

7

3

20. 8.7 16.

8.2 16. 17.

1.8 6.2 1.2

11. 7.8 13.

14. 8.2 17.

20. 12. 10.

19. 2.5 17.

Sample Output 3:

1.8 2.5 1.2

Sample Input 4:

10

10

6.0 14. 18. 18. 8.0 11. 8.3 5.8 20. 4.2

17. 14. 15. 11. 7.3 5.2 19. 19. 20. 18.

14. 12. 1.8 19. 17. 9.7 19. 11. 4.6 10.

14. 10. 14. 11. 5.3 1.8 3.9 15. 12. 8.8

8.2 3.0 8.7 5.8 12. 2.4 6.5 7.8 15. 16.

5.1 16. 11. 1.4 20. 1.2 9.5 19. 1.3 10.

5.5 17. 5.8 20. 12. 3.0 5.1 1.4 17. 11.

20. 17. 7.4 17. 14. 17. 13. 3.8 4.3 7.5

18. 6.9 4.1 9.4 7.7 13. 20. 4.9 12. 4.8

15. 5.9 8.7 16. 2.7 16. 6.0 4.3 13. 12.

Sample Output 4:

5.1 3.0 1.8 1.4 2.7 1.2 3.9 1.4 1.3 4.2

Sample Input 5:

5

10

8.7 15. 6.1 11. 2.2 9.6 2.2 4.6 7.8 20. 18. 20.

18. 7.0 8.9 14. 5.7 15. 5.0 5.5

8.7 13. 17. 13. 9.7 8.8 3.5 16. 9.2 19.

4.4 8.1 10. 14. 11. 14. 12. 19. 9.0 4.7

9.7 16. 2.5 2.6 12. 18. 9.5 17. 19. 2.6

Sample Output 5:

4.4 8.1 2.5 2.6 2.2 8.8 2.2 4.6 5.0 2.6

Sample Input 6:

10

5

16. 10. 16. 6.9 15.

2.3 2.1 8.8 14. 14.

7.8 9.2 13. 14. 5.7

15. 9.3 7.2 5.0 6.2

17. 5.3 6.4 9.4 4.2

4.7 18. 18. 17. 9.9

12. 5.3 11. 16. 8.2

20. 4.6 17. 16. 7.3

3.3 8.7 5.4 7.5 16.

11. 20. 12. 9.8 20.

Sample Output 6:

2.3 2.1 5.4 5.0 4.2

Homework Answers

Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// MinElementInEachColumn.java

import java.util.Scanner;

public class MinElementInEachColumn {

   public static void main(String[] args) {
       //Declaring variables
int rows,cols;
  
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
       //Getting the inputs entered by the user
rows=sc.nextInt();
cols=sc.nextInt();
  
//Creating a double type 2-D array based on user entered rows and columns
double matrix[][]=new double[rows][cols];
  
for(int i=0;i<rows;i++)
{
   for(int j=0;j<cols;j++)
   {
       matrix[i][j]=sc.nextDouble();
   }
}
  
for(int i=0;i<cols;i++)
{
   System.out.print(columnMin(matrix,i)+" ");    
}

  
   }

   private static double columnMin(double[][] matrix, int col) {
       double min = matrix[0][col];
       //finding minimum on a column
       for (int i = 0; i < matrix.length; i++) {
      
       if (min > matrix[i][col])
       min = matrix[i][col];

       }

         
       return min;
   }

}

__________________________________

Intput:

3
7
14 4.5 20 9.3 17 4.0 6.3
7.6 20 7.5 15 19 11 9.9
4.4 2.4 16 11 13 16 14
4.4 2.4 7.5 9.3 13.0 4.0 6.3

Output:

3
7
14 4.5 20 9.3 17 4.0 6.3
7.6 20 7.5 15 19 11 9.9
4.4 2.4 16 11 13 16 14
4.4 2.4 7.5 9.3 13.0 4.0 6.3

_______________Could you plz rate me well.Thank You

Know the answer?
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
Similar Questions
SHOW ALL WORK. DO NOT USE SOFTWARE TO GENERATE ANSWERS. Calculate the R-chart and X-bar chart...
SHOW ALL WORK. DO NOT USE SOFTWARE TO GENERATE ANSWERS. Calculate the R-chart and X-bar chart limits for the data given below. Day A B C D 1 7.2 8.4 7.9 4.9 2 5.6 8.7 3.3 4.2 3 5.5 7.3 3.2 6.0 4 4.4 8.0 5.4 7.4 5 9.7 4.6 4.8 5.8 6 8.3 8.9 9.1 6.2 7 4.7 6.6 5.3 5.8 8 8.8 5.5 8.4 6.9 9 5.7 4.7 4.1 4.6 10 3.7 4.0 3.0 5.2 11 2.6 3.9...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing text files, writing functions, and program planning and development. You will read a data file and store all of the input data in a two dimensional array. You will perform calculations on the data and store the results in the 2 dimensional array. You will sort the array and print the results in a report. Instructions You will read in the same input file...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Assuming that the population standard deviation is unknown, calculate the 95% confidence interval of the population...
Assuming that the population standard deviation is unknown, calculate the 95% confidence interval of the population mean. The following is the data. Calculating Process should be shown by Excel (Formulas). What formulas in statistics are used? 7 21 23 24 18 16 2 19 11 6 3 13 17 9 5 12 13 17 4 14 15 25 12 24 22 14 14 20 15 11 26 17 21 11 4 13 16 14 13 14 25 23 9 15...
Test, at the 1% level of significance, whether the average business has more than 15 employees....
Test, at the 1% level of significance, whether the average business has more than 15 employees. Answer using excel. Employees 14 17 17 6 8 17 21 16 6 17 11 17 15 16 20 19 6 12 17 22 20 17 11 11 9 22 17 18 21 20 26 7 16 19 18 11 21 17 25 16 22 14 14 16 18 20 21 11 19 13 6 11 19 14 18 31 13 15 17 21...
A study was conducted to investigate the effectiveness of three different methods to lower the blood...
A study was conducted to investigate the effectiveness of three different methods to lower the blood pressure of individuals diagnosed with high blood pressure. The researcher was interested in the reduction of diastolic blood pressure in the subjects that were assigned to three groups. The first group took medication, the second group engaged in daily aerobic exercises, and the third group was prescribed a plant-based diet. The subjects were placed in their regiments for four weeks. Diastolic blood pressure was...
The owner of Maumee Ford-Volvo wants to study the relationship between the age of a car...
The owner of Maumee Ford-Volvo wants to study the relationship between the age of a car and its selling price. Listed below is a random sample of 12 used cars sold at the dealership during the last year. Car Age (Years) Selling Price ($000) 1 12 10.3 2 10 9.2 3 15 4.6 4 18 4.2 5 12 5.1 6 10 11.6 7 12 8.0 8 16 7.8 9 14 7.8 10 18 4.3 11 8 10.0 12 8 8.8...
The table below contains two samples (X and Y). Please construct a test where the null...
The table below contains two samples (X and Y). Please construct a test where the null hypothesis is that the population mean Y exceeds the population mean X by exactly 3. Please note that we don't know the population standard deviations and can't assume that they are equal. Please state the p-value of your test. X Y 15 13 10 13 11 12 12 19 11 14 17 15 11 19 16 18 15 14 10 12 17 12 16...
Part A. In the past it has been found that the arrival time have a population...
Part A. In the past it has been found that the arrival time have a population mean value of μ = 13 and a population standard deviation of σ = 6.26. Using the given data, test whether this mean has changed. Use the critical value approach to test the hypothesis. The significance level alpha is set at 0.05 . The original data of time taken is given below. Show the process by using excel (Formulas). Part B. Test the hypothesis...