Matrix Manipulation in java
Description : To print sum of all values of matrix in java
import java.util.Scanner;
/**
* @author BlackBery
*
*/
public class MatrixDiagonal {
private int [][]matrix = null;
private Scanner sc = null;
public MatrixDiagonal() {
matrix = new int[3][3];
}
public static void main(String[] args) {
MatrixDiagonal md = new MatrixDiagonal();
md.getMatrixValues();
md.showMatrix();
md.computeValue();
}
private void computeValue() {
int sum = 0;
for(int row = 0; row < 3 ; row ++){
for(int col =0; col col){
sum = sum + matrix[row][col];
}
}
}
System.out.println(sum);
}
private void showMatrix() {
for(int row = 0; row < 3 ; row ++){
for(int col =0; col < 3; col ++ ){
System.out.print(matrix[row][col]+"\t");
}
System.out.println();
}
}
private void getMatrixValues() {
sc = new Scanner(System.in);
System.out.println(" Enter values ");
for(int row = 0; row < 3 ; row ++){
for(int col =0; col < 3; col ++ ){
matrix[row][col] = sc.nextInt();
}
}
}
}
You have provided an awesome website.
ReplyDeleteHere is my webpage : Digital Printing Melbourne
Hmm is anyone else exреriencing ρroblems wіth the images on this blog loaԁing?
ReplyDeleteI'm trying to determine if its a problem on my end or if it's thе
blog. Any ѕuggestions would be greаtlу appгeciаted.
Heгe is my weblog; buy followers