Question

In: Computer Science

Problem Description: Write a method that returns the smallest element in a specified column in a...

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.

Solutions

Expert Solution

import java.util.Scanner; //reads data from input stream
public class MatrixColumnMin
{
public static double columnMin(double[][] m,int columnIndex)
{
double min=m[0][columnIndex];
int i;
for(i=0;i<m.length;i++)
{
if(min>m[i][columnIndex])
min=m[i][columnIndex];
}
return min;
}
public static void main(String[] args)
{
int rows,columns;
Scanner input=new Scanner(System.in);
System.out.println("Enter rows and columns of matrix");
rows=input.nextInt();
columns=input.nextInt();
double[][] matrix=new double[rows][columns];
System.out.println("Enter elements");
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
matrix[i][j]=input.nextDouble();
}
for(int j=0;j<columns;j++)
System.out.println("The minimum element in column "+j+" is "+columnMin(matrix,j));
}
}

Output


Related Solutions

Using Java Write a method that returns the index of the smallest element in an array...
Using Java Write a method that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header:   public static int indexOfSmallestElement (double[] array)
Write a function that takes a valid stringlist and returns the index of the smallest element...
Write a function that takes a valid stringlist and returns the index of the smallest element in the list represented by the stringlist. You may not use split(). Examples: >>> stringlist min index('[123,53,1,8]') # 1 is smallest2 >>> stringlist min index('[1,2,345,0]') # 0 is smallest3 >>> stringlist min index('[5] ') # 5 is smallest0
write a method that returns the index of the second smallest element in an array of integers. If the number of such elements is greater than 1.
write a method that returns the index of the second smallest element in an array of integers. If the number of such elements is greater than 1. return the second smallest index. Use the following header:public static int index of seconds sma11eststenent tint array
Problem 3: Minimum In this problem, we will write a function to find the smallest element...
Problem 3: Minimum In this problem, we will write a function to find the smallest element of a list. We are, in a sense, reinventing the wheel since the min() function already performs this exact task. However, the purpose of this exercise is to have you think through the logic of how such a function would be implemented from scratch. Define a function named minimum(). The function should accept a single parameter named x, which is expected to be a...
Write a Java method that returns the index of the largest element in an array of...
Write a Java method that returns the index of the largest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: 
 public static int indexOfLargestElement(double[] array)
 Write a test program that prompts the user to enter ten numbers, invokes this
method to return the index of the largest element, and displays the index.
Write a method in JAVA, called binarySearch, that returns the index of the key element if...
Write a method in JAVA, called binarySearch, that returns the index of the key element if found in the array, otherwise it will return the value of minus(insertion point +1). In main, use an initializer list create an array of ints called nums holding the following values: 1, 4, 13, 43, -25, 17, 22, -37, 29. Test your binarySearch method on nums with a key value number in it (e.g. 4) and one that is not (e.g. 100). Ex. Given...
Write a method called mode that returns the most frequently occurring element of an array of...
Write a method called mode that returns the most frequently occurring element of an array of integers. Assume that the array has at least one element and that every element in the array has a value between 0 and 100 inclusive. Break ties by choosing the lower value. For example, if the array passed contains the values [27, 15, 15, 11, 27], your method should return 15. write a version of this method that does not rely on the values...
Question 1: Write a method getSmallest(), which returns the smallest number in the linked list. Question...
Question 1: Write a method getSmallest(), which returns the smallest number in the linked list. Question 2: Write a member method getPosition(int entry) which returns the position of the entry is in the linked list. If the entry is not in the list, return -1. Please use C++ language for both questions, I only need functions.
Match the economic concepts given in COLUMN A with its description in COLUMN B. Write down...
Match the economic concepts given in COLUMN A with its description in COLUMN B. Write down the question number and the correct letter next to it. E.g. 2.11 A COLUMN A COLUMN B 2.1 Production Possibility Frontier (PPF)    a.All people who live together and who make joint economic decisions or who are subjected to others who make such decision. 2.2 Cross elasticity of demand b. Monetary payments for the factors of production and other inputs bought or hired by...
   Method sandwiched returns true if num is in the element before and after       ...
   Method sandwiched returns true if num is in the element before and after            an element that is not equal to num           sandwiched([4,5,4,6,7,3], 4) returns true           sandwiched([2,1,2], 2) returns true           sandwiched([3,3,3], 3) returns false           sandwiched([4,5,6,4], 4) returns false            sandwiched([1,1,2,3,1,4,1], 1) returns true           @param nums Integer ArrayList            @param num integer           @return true if a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT