Ledger Nano X - The secure hardware wallet
SHARE
TWEET

AO LO ZIPA

a guest Apr 10th, 2020 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //*************** THE TESTS ******************//
  2. int[] arr = {0,1,0,3,12};
  3.         int[] arr2 = {0,0,1,2,3};
  4.  
  5.         int[] arr3 = {2,3,1,0,0};
  6.         int[] arr4 = {9,0,8,7,0};
  7.  
  8.         printArr(takeZeroToTheEnd(arr));
  9.         System.out.println("\n");
  10.         printArr(takeZeroToTheEnd(arr2));
  11.         System.out.println("\n");
  12.         printArr(takeZeroToTheEnd(arr3));
  13.         System.out.println("\n");
  14.         printArr(takeZeroToTheEnd(arr4));
  15.  
  16. // ************* THE CODE ******************//
  17.  
  18. public static int[] takeZeroToTheEnd(int[] arr) {
  19.         int guardIndex = 0;
  20.         int temp1 = 0;
  21.         int countZero = 0;
  22.  
  23.         for (int i = 0; i < arr.length -1; i++) {
  24.             countZero++;
  25.         }
  26.         for (int i = 0; i < arr.length; i++) {
  27.             System.out.println(i);
  28.             if (arr[i] != 0) {
  29.                 temp1 = arr[i];
  30.                 arr[guardIndex] = temp1;
  31.                 guardIndex++;
  32.             }
  33.         }
  34.         for (int i = arr.length-1; i > arr.length - countZero+1 ; i--) {
  35.             arr[i] = 0;
  36.         }
  37.         return arr;
  38.     }
  39.  
  40.  
  41. /// ******************** THE GAV ***********************//
  42.     YOU!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top