August 09, 2012

How to print matrix in java

Matrix Manipulation in java


Description : To print sum of all values of matrix in java


 import java.util.Scanner;

/**
* +belazy 
*/
/**
* @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();
}
}
}
}




2 comments:

  1. You have provided an awesome website.
    Here is my webpage : Digital Printing Melbourne

    ReplyDelete
  2. Hmm is anyone else exреriencing ρroblems wіth the images on this blog loaԁing?
    I'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

    ReplyDelete

Your feedback may help others !!!

Facebook comments