2016-11-13 150 views
0

我在java中有一個程序,並且在控制檯上顯示矩陣int [] []的結果時出現了一些問題。顯示矩陣double int java

public class Matrix_complexSync { 
private int m; 
private int n; 
private int[][] matrix1; 
private int[][] matrix2; 
private int[][] matrix3; 
private int[][] tempResult; 
private int[] counter; 

private int firstNoThreads; 
private int secondNoThreads; 

public Matrix_complexSync(int m, int n) { 
    this.m = m; 
    this.n = n; 
    matrix1 = new int[m][n]; 
    matrix2 = new int[m][n]; 
    matrix3 = new int[m][n]; 
    tempResult = new int[m][n]; 
    counter = new int[m]; 
} 

public void initialiseMatrix(int maxValue, int firstNoThreads, int secondNoThreads) { 
    Random randomGenerator = new Random(); 
    for (int i = 0; i < m; i++) { 
     for (int j = 0; j < n; j++) { 
      matrix1[i][j] = randomGenerator.nextInt(maxValue); 
      matrix2[i][j] = randomGenerator.nextInt(maxValue); 
      matrix3[i][j] = randomGenerator.nextInt(maxValue); 
     } 
    } 

    this.firstNoThreads = firstNoThreads; 
    this.secondNoThreads = secondNoThreads; 
} 

public int[][] matrixMultiplicationLineThread() throws InterruptedException { 
    // my code 

    return tempResult; 
} 
} 

和主:我對類矩陣的計算代碼

public static void main(String[] args) throws InterruptedException{ 
    Matrix_complexSync m = new Matrix_complexSync(2,2); 
    m.initialiseMatrix(5, 1,1); 
    int res[][] = m.matrixMultiplicationLineThread(); 
    System.out.println("The result is : " + Arrays.toString(res)); 
} 

和控制檯顯示我:

The result is : [[[email protected], [[email protected]] 

任何想法,請以顯示良好形式的矩陣的計算方法?

+1

循環它並打印每個值? – UnholySheep

回答

0
for (int[] row : res) 
    { 
     System.out.println(Arrays.toString(row)); 
    }