-1
I have two lists of 50 numbers.
One has multiples of 3
and the other multiples of 7
.
Code:
public static void main(String[] args) {
List<Long> lista1 = new ArrayList<>();
List <Long> lista2 = new ArrayList<>();
for (long a = 1; a <= 50; a++) {
long b,c;
b = a*3;
c = a*7;
lista1.add(b);
lista2.add(c);
}
System.out.println("Lista(1)="+lista1);
System.out.println("Lista(2)="+lista2);
}
}
See working on repl: https://repl.it/repls/TragicSiennaBoolean
I need only the repeating numbers between the two lists to be printed, so only:
List(3)=[21, 42, 63, 84, 105, 126, 147]
All right Elipe, is not working on Repl.
– William
I got it right here... but like I would with Big Integer???
– William
@William the same way. You’d just have to change your List for
List<BigInteger>
and add the Bigintegers for her.– Felipe Marinho
Thanks friend!
– William
Hello Felipe Marinho, the only problem is that if the numbers were not in a list, (List) for example, as it would be to do the same system, print only the repeated numbers of two different formulas??
– William
"retainAll" does not only work for printed numbers that are not within a list...
– William
@William O retainAll is a method of API of Collections. You can apply this operation to any collection that implements it (List, Set, Queue, etc) of any type of element (String, Double, any class). If you have, for example, arrays storing the values, just create any collection from them and run the method. In case you, for some reason, want to do "on the arm", take a look at how this method is implementing in
ArrayList
here.– Felipe Marinho
So Felipe, I posted a new question because I can’t print without the lists...
– William
Alright Felipe, I posted another question.. https://answall.com/questions/275985/como-imprimir-apenas-n%C3%Bameros-que-se-repetem-entre-duas-formulas-diferentes
– William