//please help I can’t figure out how to print and can’t get the random numbers to print. Please help, I have the prompt attached. Thanks
import java.util.*;
public class Test {
/** Main method */
public static void main(String[] args) {
double[][] matrix = getMatrix();
// Display the sum of each column
for (int col = 0; col < matrix[0].length; col++) {
System.out.println(
"Sum " + col +
" is " + sumColumn(matrix, col));
}
}
/** getMatrix initializes an array with user input values */
public static double[][] getMatrix() {
final int ROWS = 3;
final int COLUMNS = 2;
double[][] m = new double[ROWS][COLUMNS];
// Prompt the user to enter a 3-by-4 matrix
for (int row = 0; row < m.length; row++)
for (int col = 0; col < m[row].length; col++)
System.out.println(20+(int) (Math.random() *50));
return m;
}
/** sum returns the sum of the elements in columnIndex */
public static double sumColumn(double[][] m, int columnIndex) {
double sum = 0;
for (int row = 0; row < m.length; row++) {
sum += m[row][columnIndex];
}
return sum;
}
}
I have done the first 4 parts of the problem. The last part is trivial and can be added easily in the code
import java.util.*;
public class Test {
/** Main method */
public static void main(String[] args) {
double[][] matrix = createArray();
double[] sum = new double[matrix[0].length];
for (int i = 0; i < matrix[0].length; i++) {
sum[i] = sumColumn(matrix, i);
}
printResult(matrix, sum);
}
/** getMatrix initializes an array with user input values
*/
public static double[][] createArray() {
final int ROWS = 3;
final int COLUMNS = 2;
double[][] m = new double[ROWS][COLUMNS];
// Create a random 3-by-2 matrix
for (int row = 0; row < ROWS; row++)
for (int col = 0; col < COLUMNS; col++)
// For every element of the 3x2 matrix
m[row][col] = 20 + (Math.random() * 30); // Genereate a random
double between 20 and 50 and insert it into the matrix
return m;
}
/** sum returns the sum of the elements in columnIndex */
public static double sumColumn(double[][] m, int columnIndex)
{
double sum = 0;
for (int row = 0; row < m.length; row++) {
sum += m[row][columnIndex];
}
return sum;
}
/* print the matrix */
public static void printResult(double[][] m, double [] sum) {
System.out.println("The matrix is: ");
for(int row = 0; row < m.length; row++) {
System.out.printf(" ");
for(int col = 0; col < m[0].length; col++) {
System.out.printf("%6.1f ", m[row][col]);
}
System.out.print("\n");
}
System.out.printf("Sum: ");
for (int i = 0; i < sum.length; i++) {
System.out.printf("%6.1f ", sum[i]);
}
}
}
Output:

//please help I can’t figure out how to print and can’t get the random numbers to...
JAVA Write a method that returns the sum of all the elements in a specified column in a matrix using the following header: public static double sumColumn(double [][] m, int columnIndex) Write another method that returns the sum of all the elements in a specified row in a matrix using the following header: public static double sumRow( double [][] m, int rowIndex) Write a test program that reads a 3-by-4 matrix and displays the sum of each column and sum...
Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()" public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...
(Sum elements column by column) Write a method that returns the sum of all the elements in a specified column in a matrix using the following header: public staticdouble sumColumn( double[] [] m, int columnIndex) Write a test program that reads a 3- by- 4 matrix and displays the sum of each column.
1.Write a Java program that computes the average of the values of a row in a twodimensional array. You should create a method with the following header: public static double averageRow(double[][] array, int row) Write a test program that reads a matrix from the user and a row index to calculate the average on. Print the result. 2.A square matrix is said to be an upper triangular matrix if the value of the cell is 0 when row > column....
please use eclipse
the sample output is incorrect
CPS 2231 Chapter 8 Lab 1 Spring 2019 1. Write a class, SumOrRows. The main method will do the following methods: a. Call a method, createAndFillArray which: defines a 2 dim array of 3 rows and 4 columns, prompts the user for values and stores the values in the array. b. Calls a method, printArray, which: prints the Array as shown below c. Cails a method, calcSums, which: returns à 1 dimensional...
Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user ! Java only using J option pane, you cannot use ulti or anything else only J option pane Program compiles but does not print the array correctly! import javax.swing.JOptionPane; public class programtrial { public static void main(String[] args) { int newclass = 0; int countclass = 0; final int class_Max = 8; int[] classarray =...
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...
Need help figuring this out Write a program that reads in a sequence of numbers (doubles) from standard input until 0 is read, and stores them in an array, This part is done using iteration (loop). You may assume that the maximum size of the array will not be more than 100. Your program computes the maximum number stored in the array, the count of negative numbers, and computes the sum of positive numbers, using recursion. You need to have...
Below is my code and the instructions for the code. I can't figure out what's wrong. Please help. Tasks This lab has two parts: Writing a searching function for 1D arrays. Writing a simple class. Part 1 – Searching Continuing with arrays, we will now expect you to find information in an array and derive useful properties from the information stored in an array. Start Eclipse. Change the workspace directory location to something "safe". You may want to temporarily choose...