- import java.util.ArrayList;
- public class Main {
- public static void main(String args[]) {
- int[] arr = { 1, 3, 5, 1, 6, 8, 41, 74, 35, 124, 17, 3, 8, 76, 56, 89 };
- int[] num = (int[]) jiShu(arr);
- for (int i = 0; i < num.length; i++) {
- System.out.println(num[i]);
- }
- }
- private static int[] jiShu(int[] arr) {
- ArrayList<Integer> list = new ArrayList<>();
- for (int i = 0; i < arr.length; i++) {
- if (arr[i] % 2 != 0) {
- list.add(arr[i]);
- }
- }
- int[] num = new int[list.size()];
- for (int i = 0; i < list.size(); i++) {
- num[i] = list.get(i);
- }
- return num;
- }
- }
复制代码 |