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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need Help With this problem

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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());
    }
    Last edited by ik1dxD; March 14th, 2014 at 03:41 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,090
    My Mood
    Mellow
    Thanks
    244
    Thanked 752 Times in 738 Posts

    Default 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.

Similar Threads

  1. Catch block problem. Please fix my problem.
    By damnitsme in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 3rd, 2014, 01:49 AM
  2. Problem with Project Euler problem 18
    By sara_magdy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 19th, 2013, 01:46 PM
  3. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  4. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 08:59 AM
  5. Java program for 2-D Array Maze
    By Peetah05 in forum Collections and Generics
    Replies: 11
    Last Post: May 8th, 2009, 05:30 AM