skilletwaffles

compact

Dec 18th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. //array is the array and i is the length of the array.
  2. public int[] compactThis(int[] array, int i)
  3. {
  4.     //will add the int given by check int to the specified cell
  5.     int addInt = 0;
  6.  
  7.     //checks if cell contains a 0
  8.     int checkInt = 0;
  9.  
  10.     //stores value of non zero cell
  11.     int num = 0;
  12.  
  13.     for(int loop = 0; loop<i; loop++)
  14.     {
  15.         if(array[loop] !=0)
  16.         {
  17.             num = array[loop];
  18.             array[addInt] = num;
  19.             addInt++;
  20.         }
  21.         else
  22.             checkInt++;
  23.     }
  24. return array;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment