Guest User

Untitled

a guest
Feb 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1.     public static void main(String args [])
  2.     {
  3.  
  4.         int a [] = new int [10];
  5.         int b [] = new int [10];
  6.         int c [] = new int [10];
  7.         int d [] = new int [10];
  8.         int e [] = new int [10];
  9.         int f [] = new int [10];
  10.        
  11.         //instead of having 6 different arrays, why not just make 1 array?
  12.        
  13.         int g [] [] = new int[6][]; //allocate memory for 6 arrays.
  14.  
  15.         // above is still just an array of 6 arrays:
  16.         // why not make one array, and index it as a 2d array:
  17.         int h* = new int[10 * 6 /* width * height */];
  18.  
  19.         // access by:
  20.         int test = h[y * width + x]; // x being column, y  being row, both starting at 0
  21.  
  22.         // also, shame on everyone for not cleaning up after themselves :P
  23.         delete [] h;
  24.         delete [] g
  25.        
  26.         return;    
  27.     }
Add Comment
Please, Sign In to add comment