Implementar metodo que concatena todos los numeros positivos de dos listas.
class ConcatPositiveNumbersProblem {
public static ArrayList<Integer> concatPositiveNumbers(ArrayList<Integer> l1, ArrayList<Integer> l2) {
ArrayList<Integer> numbers = new ArrayList<>();
for (int num : l1) {
if (num >= 0) {
numbers.add(num);
}
}
for (int num : l2) {
if (num >= 0) {
numbers.add(num);
}
}
return numbers;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Integer> list1 = readArrayList(scanner);
ArrayList<Integer> list2 = readArrayList(scanner);
ArrayList<Integer> result = concatPositiveNumbers(list1, list2);
result.forEach(n -> System.out.print(n + " "));
}
private static ArrayList<Integer> readArrayList(Scanner scanner) {
return Arrays
.stream(scanner.nextLine().split("\\s+"))
.map(Integer::parseInt)
.collect(Collectors.toCollection(ArrayList::new));
}
}