Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class exercise200 {
- public static void main(String args[]) {
- System.out.println("Entre the size of the array");
- int length = ITI1120.readInt();
- System.out.println("Entre the values");
- int[] nums = new int[length];
- for(int i=0; i<nums.length; i++){
- nums[i]= ITI1120.readInt();
- }
- //int[] tmp = new int[length];
- printArray(nums);
- Zeros(nums);
- System.out.println();
- printArray(nums);
- }
- public static void Zeros(int[] arr){
- int count = 0;
- for (int i = 0; i < arr.length; i++)
- if (arr[i] != 0)
- arr[count++] = arr[i]; // here count is incremented
- while (count < arr.length)
- arr[count++] = 0;
- }
- public static void printArray(int[] array)
- {
- for(int i=0; i<array.length; i++)
- System.out.print(array[i] + " ,");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement