fork(1) download
  1. class ArrayTens {
  2.  
  3. public static void main(String[] args) {
  4. int [] arr = { 1, 10, 10, 2 };
  5. int [] res = ArrayTens.withoutTen(arr);
  6. printArray(res);
  7. }
  8.  
  9. public static int[] withoutTen(int[] nums) {
  10. int slow = 0;
  11.  
  12. for (int fast = 0; fast < nums.length; fast++) {
  13. if (nums[fast] != 10) {
  14. nums[slow] = nums[fast];
  15. slow++;
  16. }
  17. }
  18.  
  19. for (int i = slow; i < nums.length; i++) {
  20. nums[i] = 0;
  21. }
  22. return nums;
  23. }
  24.  
  25. public static void printArray(int[] arr) {
  26. for (int i : arr) {
  27. System.out.print( i + ",");
  28. }
  29. }
  30.  
  31. }
  32.  
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
1,2,0,0,