0
Staff need help for an activity:
Consider three vectors of numbers.
Write a program to print out the largest Twin Primes numbers in each vector.Which are the largest twin prime numbers considering all the elements. (In all vectors)
OBS: the solution should optimize the running time.
You may not use the Collections API.
I’m having difficulty in the Threads implementation part where I have to allocate the optimization for the runtime.
public class NumeroPrimoGemeo {
public List<Integer> retornaNumeroGemeos(Integer comeco, Integer fim){
int i = comeco;
while(i <= fim){
if(verificaNumeroPrimo(i)){
int x = i + 2;
if(verificaNumeroPrimo(x)){
List<Integer> integers = new ArrayList<>();
integers.add(i);
integers.add(x);
return integers;
}
}
i++;
} throw new RuntimeException("Não há nenhum numero primo gemeos ");
}
Can someone make a code and explain to me with comments?
Which part are you struggling with?
– Math
That’s not quite how the site works, young man. Look, [Ask], how to create a [mcve] and also do the [tour]. Try to explain to us what your difficulty is and how we can help you achieve the expected result. Otherwise it seems you want us to do your exercise for you.
– Jéf Bueno
I’m having difficulty in the Threads implementation part where I have to allocate the optimization for the runtime.
– Jhon
public class Numeroprimogemeo { public List<Integer> returnNumeroGemeos(Integer starts, Integer ends){ int i = start; while(i <= end){ if(verificaNumeroPrimo(i)){ int x = i + 2; if(verificaNumeroPrimo(x)){ List<Integer> integers = new Arraylist<>(); integers.add(i); integers.add(x); Return integers; } } i++; } throw new Runtimeexception("There are no prime numbers twins"); }
– Jhon
Be careful that the Collections API includes
Arraylist
, that you’re using at work. Unless you’re talking about classjava.util.Collections
.– Piovezan