java - 2d array inside another array? -


is there anyway make array hold 2d array?

i want somehow hold value of matrixfinal based on user enters can later use it. think i'd able if can hold these values in array these 2d arrays...

how go doing this?

public class driver { public static void main(string[] args) {     int i, j, k, l ;     int sum = 0 ;     int matrixacolumnsize   ;     int matrixarowsize      ;     int raisebypower        ;       // querying user     matrixarowsize      =   tools.queryforint("enter row size of matrix a: ") ;     matrixacolumnsize   =   tools.queryforint("enter column size of matrix a: ") ;     tools.verifymatrixsize(matrixacolumnsize, matrixarowsize) ;  // verification of matrix size 10x10 max     tools.verifymultiplication(matrixarowsize, matrixacolumnsize) ; // verification of matrix size     raisebypower        =   tools.queryforint("by power raise matrix? ") ;      tools.verifymatrixpower(raisebypower) ; // verification of power. ^6 max      //making matrices     int matrixa[][] = new int[matrixarowsize][matrixacolumnsize] ;     int matrixfinal[][] = new int [matrixarowsize][matrixacolumnsize] ;       // querying elements of matrix             (i = 0; < matrixarowsize; i++) {                 (j = 0; j < matrixacolumnsize; j++) {                     matrixa[i][j] = tools.queryforint("enter element in matrix a" + (i+1) + "," + (j+1) + " :" ) ; }}      // multiplying matrices             if (raisebypower == 1) {                 (i = 0; < matrixarowsize; i++) {                     (j = 0; j < matrixacolumnsize; j++) {                         matrixfinal[i][j] = matrixa[i][j] ;                     }                 }              } else if (raisebypower == 2) {             (i = 0; < matrixarowsize; i++)             {                 (j = 0; j < matrixacolumnsize; j++)                  {                     (k = 0; k < matrixarowsize; k++)                      {                         sum = sum + matrixa[i][j] * matrixa[i][j] ;                     }                      matrixfinal[i][j] = sum ;                     sum = 0 ;                 }             }              } else if (raisebypower == 3) {                 (i = 0; < matrixarowsize; i++)                 {                     (j = 0; j < matrixacolumnsize; j++)                      {                         (k = 0; k < matrixarowsize; k++)                          {                             sum += matrixa[i][j] * matrixa[i][j] * matrixa[i][j] ;                             sum = 0 ;                         }                         matrixfinal[i][j] = sum ;                      }                     }             } else if (raisebypower == 4) {                 (i = 0; < matrixarowsize; i++)                 {                     (j = 0; j < matrixacolumnsize; j++)                      {                         (k = 0; k < matrixarowsize; k++)                          {                             sum += matrixa[i][j] * matrixa[i][j] * matrixa[i][j] * matrixa[i][j] ;                         }                         matrixfinal[i][j] = sum ;                         sum = 0 ;             }                 }} else if ( raisebypower == 5) {                     (i = 0; < matrixarowsize; i++)                     {                         (j = 0; j < matrixacolumnsize; j++)                          {                             (k = 0; k < matrixarowsize; k++)                              {                                 sum += matrixa[i][j] * matrixa[i][j] * matrixa[i][j] * matrixa[i][j] * matrixa[i][j] ;                             }                             matrixfinal[i][j] = sum ;                             sum = 0 ;                 }                 }                 } else if ( raisebypower == 6) {                     (i = 0; < matrixarowsize; i++)                     {                         (j = 0; j < matrixacolumnsize; j++)                          {                             (k = 0; k < matrixarowsize; k++)                              {                                 sum += matrixa[i][j] * matrixa[i][j] * matrixa[i][j] * matrixa[i][j] * matrixa[i][j] * matrixa[i][j] ;                             }                             matrixfinal[i][j] = sum ;                             sum = 0 ;                 }                 }                 }               system.out.println("matrix power of " + raisebypower + " is: ") ;              (i = 0; < matrixarowsize; i++) {                 (j = 0; j < matrixacolumnsize; j++)                      system.out.print(matrixfinal[i][j] + "\t") ;                  system.out.println();             }  

} }

you can nest arrays as want int[][][] possible, array of 2d arrays.

well, have int[][] can make

int[][][] container = new int[numberofmatrixes][matrixsize][matrixsize]; 

and add matrixa or matrixfinal:

container[index] = matrixa; 

and values matrixa:

int = container[index][index2][index3]; 

where before have used

int = matrixa[index2][index3]; 

you treat 'container' array other array first matrix added @ container[0], second @ container[1] , on. have remember matrix @ index yourself.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -