Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Thread: Need Help With this problem

1. Need Help With this problem

A twin prime is a prime number that differs from another prime number by exactly 2. For
example, 3 and 5 are twin primes, since 3 and 5 are each prime and differ by 2
(likewise, 5 and 7 are also twin primes).
Complete the twins() method, which takes an integer argument n and prints all the
sets of twin primes that are less than n, one pair per line. The method does not return
any value. For example, twins(15) would print
(3, 5)
(5, 7)
(11, 13)
Use the sieve() method from Part 1 to generate the initial list of prime numbers.

This is what I have:
public static void twins (int max)
{
ArrayList<Integer> twins= sieve(max);
new ArrayList<Integer>(max);
int index = 0;
for (index = 0; twins.size() - 1 > index; index++)
{
if (twins.get(index+1) - twins.get(index) == 2)
{
System.out.println(twins.size()+","+ twins.size());
}

2. Re: Need Help With this problem

Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

Please post your code correctly. What do you need help with? Please ask a specific question so that we know where to start and that you want something other than someone to just complete your code for you.