Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //array is the array and i is the length of the array.
- public int[] compactThis(int[] array, int i)
- {
- //will add the int given by check int to the specified cell
- int addInt = 0;
- //checks if cell contains a 0
- int checkInt = 0;
- //stores value of non zero cell
- int num = 0;
- for(int loop = 0; loop<i; loop++)
- {
- if(array[loop] !=0)
- {
- num = array[loop];
- array[addInt] = num;
- addInt++;
- }
- else
- checkInt++;
- }
- return array;
- }
Advertisement
Add Comment
Please, Sign In to add comment