44% Wed Mar 29 4 53 22 PM E Chrome File Edit View History Bookmarks People Windo
ID: 3807459 • Letter: 4
Question
44% Wed Mar 29 4 53 22 PM E Chrome File Edit View History Bookmarks People Window Hel C chegg Study I Guided x C chegg studyIGuided x C Search Textbook Soluti x Lab 11.pdf ksuweb. kennesaw ed u/~hhaddad/Spring2017/CS1301/Lab1 1.pdf D cs 1301: Program.. M Inbox jking199@s. Apps YouTube home CompTIA A+ Certifi OWILink Online Ca Lab11 pdf to add two matrices. The heade Exercise 1: Design and implement a Java program for programming exercise 8.1, page 305 (name it (doubleCl CJ a, double[] CJ b) olumns) as described in the problem statement. Write method sumColumn0 as specified. To test ray SumAr this method, the main method of your program prompts the user to enter a 3-by-4 matrix and displays the sum of each column calling method sumColumns Design the main method of your program such that it allows the user to re-run the program with different inputs (i.e., use a loop). Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable. Exercise 2 Design and implement a Java program for programming exercise 8.5, page 306 (name AddMatricies) as described in the problem statement. Write method addMatrix0 as specified. To test this Programming Exercises 307 method, the main method of your program prompts the user to enter two matrices that have the same dimensions, and then display their sum as shown in the sample run. Design the main method of your program and the uch that it allows the user to re-run the program with different inputs (i.e., use a loop). Document your code objects when applicable. ch ele d organize and s pace the outputs properly. Use escape characters and formattin PM nt a Java program for programming exercise 8.13, page 310 (name it LocateLargestElement) as described in the problem statement. Write method locateLargest0 as specified. Notice that this method returns a one-dimensional array that contains two elements. These two elements VideoNote indicate the row and column indices of the largest element in the two-dimensional array. To test this method, the Multiply two matrices main method of your program prompts the user to enter a two-dimensional array and displays the location of the largest element in the array. Use the sample run to format your output. Design the main method of your program such that it allows the user to re-run the program with different inputs (i.e., use a loop). Document your code, and organize and space the outputs properly. Use escape characters and formatting objects when applicable. Exercise Design and implement a Java program for programming exercise 8.26, page 315 (name it orting) as described in the problem statement. Write method sortRows0 as specified (you may change PM the element type to integer). Notice that this method returns a new array, the original array still unchanged. See Chapter 7 for how to sort one-dimensional array. To test this method, the main method of your program prompts a Course Schedule for docx Show All op: 1Explanation / Answer
AdditionOfMatrices.java
import java.util.Scanner;
public class AdditionOfMatrices {
public static void main(String[] args) {
//Declaring Two dimensional arrays
double matarr1[][]=new double[3][3];
double matarr2[][]=new double[3][3];
//Scanner object is used to get the inputs from the keyboard
Scanner sc=new Scanner(System.in);
//For loop which get the input from the user and fills into 1st matrix
System.out.print("Enter Martrix 1:");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
matarr1[i][j]=sc.nextDouble();
}
}
//For loop which get the input from the user and fills into 2nd matrix
System.out.print("Enter Martrix 2:");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
matarr2[i][j]=sc.nextDouble();
}
}
//calling the method
double sum[][]=addMatrix(matarr1,matarr2);
//Displays the result
System.out.println("The matrices area added as follows ::");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(matarr1[i][j]+" ");
}
if(i==1)
System.out.print(" + ");
else
System.out.print(" ");
for(int j=0;j<3;j++)
{
System.out.print(matarr2[i][j]+" ");
}
if(i==1)
System.out.print(" = ");
else
System.out.print(" ");
for(int j=0;j<3;j++)
{
System.out.print(sum[i][j]+" ");
}
System.out.println(" ");
}
}
// Static method which add the two matrices and returns the resultant matrix to the calling method
private static double[][] addMatrix(double[][] matarr1, double[][] matarr2)
{
double sum[][]=new double[matarr1.length][matarr1[0].length];
for(int i=0;i<sum.length;i++)
{
for(int j=0;j<sum[0].length;j++)
{
sum[i][j]=matarr1[i][j]+matarr2[i][j];
}
}
return sum;
}
}
__________________
Output:
Enter Martrix 1:1 2 3 4 5 6 7 8 9
Enter Martrix 2:0 2 4 1 4.5 2.2 1.1 4.3 5.2
The matrices area added as follows ::
1.0 2.0 3.0 0.0 2.0 4.0 1.0 4.0 7.0
4.0 5.0 6.0 + 1.0 4.5 2.2 = 5.0 9.5 8.2
7.0 8.0 9.0 1.1 4.3 5.2 8.1 12.3 14.2
_____________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.