Java array index is n/2

52 views Asked by At

I have a code that shows the Strassen Matrix Multiplication and I want to show its step by step process. The size and elements of the matrix are user-input. I have a problem with regards to showing the element at index (n/2). What should the indexes be when I show it? Thanks for the help!

Here's a part of my code:

else {
    int[][] A11 = new int[n / 2][n / 2];
    int[][] A12 = new int[n / 2][n / 2];
    int[][] A21 = new int[n / 2][n / 2];
    int[][] A22 = new int[n / 2][n / 2];
    int[][] B11 = new int[n / 2][n / 2];
    int[][] B12 = new int[n / 2][n / 2];
    int[][] B21 = new int[n / 2][n / 2];
    int[][] B22 = new int[n / 2][n / 2];
   
    split(a, A11, 0, 0);
    split(a, A12, 0, n / 2);
    split(a, A21, n / 2, 0);
    split(a, A22, n / 2, n / 2);
  
    split(b, B11, 0, 0);
    split(b, B12, 0, n / 2);
    split(b, B21, n / 2, 0);
    split(b, B22, n / 2, n / 2);
    
    System.out.println();
    System.out.println("Step by Step Operation");
    System.out.println();
    System.out.println("p1 = (" + A11[0][0] + " + " + A22 + ")(" + B11[0][0] + " + " + B22 + ")");
    System.out.println("p2 = (" + A21 + " + " + A22 + ")" + B11[0][0]);
    System.out.println("p3 = " + A11[0][0] + "(" + B12 + " - " + B22 + ")");
    System.out.println("p4 = " + A22 + "(" + B21 + " - " + B11[0][0] + ")");
    System.out.println("p5 = (" + A11[0][0] + " + " + A12 + ")" + B22);
    System.out.println("p6 = (" + A21 + " - " + A11[0][0] + ")(" + B11[0][0] + " + " + B12 + ")");
    System.out.println("p7 = (" + A12 + " - " + A22 + ")(" + B21 + " + " + B22] + ")");
0

There are 0 answers