Created
October 25, 2021 21:34
-
-
Save oriapp/b93279c31c3ce09b8935673582e05e12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class test { | |
static public void main(String args[]){ | |
int[] res = Filter(new int[]{6, 9, 2, 2, 9, 4, -3}, 9); | |
for (int i : res){ | |
System.out.println(i); | |
} | |
} | |
public static int[] Filter(int[] arr, int num){ | |
int n = countNums(arr, num); | |
int[] a = new int[n]; | |
int j = 0; | |
for(int i = 0; i < arr.length; i++) { | |
if (arr[i] != num){ | |
a[j] = arr[i]; | |
j++; | |
} | |
} | |
return a; | |
} | |
public static int countNums(int[] arr, int num){ | |
int count = 0; | |
for(int i = 0; i < arr.length; i++){ | |
if (arr[i] != num){ | |
count++; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment