Java programming with threads

Asked

Viewed 153 times

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?

  • 3

    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.

  • 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> 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"); }

  • Be careful that the Collections API includes Arraylist, that you’re using at work. Unless you’re talking about class java.util.Collections.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.