Row and columns sum
Create a java program that:
Run the program 5 times with representative sizes
Code -
import java.util.*;
public class Main
{
public static void main(String[] args) {
//reading from command line arguement , give 4 value
in command line arguemnet
//m for row
int m = Integer.parseInt(args[0]);
//n for column
int n = Integer.parseInt(args[1]);
//min value
int minValue = Integer.parseInt(args[2]);
//max value
int maxValue = Integer.parseInt(args[3]);
//create random object
Random r = new Random();
//variable and arrays decalare to use
int i, j;
int a[][] = new int[m][n];
int sumRow[] = new int[m];
int sumRows=0;
int sumCol[] = new int[n];
int sumCols=0;
//generate random value and store in array a
for(i = 0;i<m;i++){
for(j = 0;j<n;j++){
a[i][j] =r.nextInt(maxValue-minValue) + minValue;
}
}
//calculate sum of rows and store in sumRow
for(i = 0;i<m;i++){
for(j = 0;j<n;j++){
sumRow[i] += a[i][j];
}
}
//calculate sum of sum of rows
for(i = 0;i<m;i++){
sumRows+=sumRow[i];
}
//calculate sum of columns and store in sumCol
for(i = 0;i<m;i++){
for(j = 0;j<n;j++){
sumCol[i] += a[j][i];
}
}
//calculate sum of cols
for(i = 0;i<m;i++){
sumCols+=sumCol[i];
}
//print the matrix as sum
for(i = 0;i<m;i++){
for(j = 0;j<n;j++){
System.out.printf("%4d ", a[i][j]);
if(j == n-1){
System.out.print(" | "+sumRow[i]);
}
}
System.out.println();
}
System.out.println("------------------------");
for(i = 0;i<n;i++)
System.out.printf("%4d ",sumCol[i]);
System.out.printf(" |%4d",sumRows);
System.out.println("\n\n");
System.out.println("Sum rows is "+sumRows);
System.out.println("Sum columns is "+sumCols);
}
}
Screenshots -
Row and columns sum Create a java program that: Input: Receive as input in command line...
Create a program that:Receives as input in command line the sizes [rows] and [cols] of a two dimensional array, and [minValue] and [maxValue] between which the random numbers will be generated. Assume maxValue <= 999Generates two random two dimensional array with numbers between minValue and maxValue (inclusive) with the given size (rows x cols), and store them in m1 and m2Compute the sum of the two matrices and stores the result in a new matrix mSum.
this language is JAVA 2. Design a class named Location for locating a maximum value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two-dimensional array: Public static Location locateLargest(double [][] a) Create...
Write a Python program that reads user input from the command-line. The program should define a function read Position, which reads the values for t, v0, and h0. If there is an IndexError, print 'Please provide the values for t, vO, and hO on the command line.'. If t, v0, or h0 are less than 0. print 't = # is not possible.' for each variable respectively. Note that the # represents the number entered on the command-line by the...
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...
In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...
Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to square all 60 array elements. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as...
Write a Java program that calculates the sum of a variable sized matrix using a two dimensional array. (ArraySum.java) The user should provide the number of rows and columns Test multiple user inputs (3 times 2, 4 times 4, 6 times 2, etc) A sum should be created for each row, each column, and the total for the matrix Ex.: How big would you like your matrix? Rows - ? 3 Columns -? 2 Please enter your row 1? Column...
Write code to create a two-dimensional array named numbers containing 500 random numbers from 1 to 1000 inclusive. The array has 50 rows. Then walk through the array and output the random numbers 10 to a line. Format the numbers in right-aligned columns. Use the command prompt window for output. Note: do NOT create a class or main.
Code in Java and implement (source code) a program (name it WeeklyHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers’ daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers between 0 and 10 and...
Write a C function f such that … function f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...