Question
Lab Goal : This lab was designed to teach you how to use a matrix, an array of arrays. Lab Description : Load in the
Lab Goal : This lab was designed to teach you how to use a matrix, an array of arrays.
Lab Description : Load in the provided matrix and then sum up all of the cells around the provided cell locations. Include the value of the provided location as well as all of the cells within 1 cell of the provided cell.
1, 2, 3, 4, 5
6, 7, 8, 9, 0
6, 7, 1, 2, 5
6, 7, 8, 9, 0
5, 4, 3, 2, 1
The sum of 0,0 is 16.
The sum of 1,1 is 41.
Sample Data :
2 2
0 0
4 3
4 4
2 4
1 3
Sample Output :
Matrix values
1 2 3 4 5
6 7 8 9 0
6 7 1 2 5
6 7 8 9 0
5 4 3 2 1
The sum of 2,2 is 58.
The sum of 0,0 is 16.
The sum of 4,3 is 23.
The sum of 4,4 is 12.
The sum of 2,4 is 25.
The sum of 1,3 is 37.
//Main.Java
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;
public class Main
public static void main( String args[] ) throws IOException
{
Scanner file = new Scanner (new File("matsum.dat"));
int times = f.nextInt();
MatrixSumming2 ms = new MatrixSumming2();
for( int dx = 0; dx < times; dx++ )
{
int r = f.nextInt();
int c = f.nextInt();
System.out.println("The sum of " + r + "," + c + " is " + ms.sum(r+1,c+1) );
}
}
} //Matrixsumming2.java method
import java.util.*;
import java.io.*;
public class MatrixSumming2
{
private int[][] m = {{5,6},{7,8},{3,4}}; //load in the matrix values
public int sum( int r, int c )
{
return 0;
}
public String toString()
{
return "";
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started