Results 1 to 5 of 5
  1. #1
    grjmmr is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default finish the code please

    I am not a programmer. I am a math student doing my senior thesis on prime numbers. Something I would like to do is run a mersenne prime number program and see how long it will take before my computer dies to show the limitations of current technology. I found this script online. BTW, if you recognize who wrote this please leave a name so I can give credit during my speach. Also can I just compile it and run it or do I need to do anything else to it? Also does anyone have any suggestions for an easy compiler to use?

    Thank you for your time

    Will

    import
    java.math.BigInteger;
    import java.util.Scanner;
    public class MersennePrime {
    public static void main(String args[]) {
    Scanner limiter = new Scanner(System.in);
    System.out.println("Enter the max number of Mersenne Primes you want to find-->");
    int counter = limiter.nextInt();
    BigInteger prime = BigInteger.valueOf(2);
    BigInteger mprime = BigInteger.valueOf(1);
    String columnmaker = "|";
    while (counter>0) {
    boolean primechecker =true;
    BigInteger divisor = BigInteger.valueOf(2);
    BigInteger x =prime;
    BigInteger root = BigInteger.valueOf (0);
    BigInteger y =BigInteger.valueOf(-1);
    while (x.compareTo(BigInteger.valueOf (0))>=0) {
    x = x.add(y);
    y=y.add(BigInteger.valueOf(-2));
    root=root.add(BigInteger.valueOf(1));
    if (x.compareTo(BigInteger.valueOf(0))==0) {
    x=BigInteger.valueOf(-1);
    }
    }
    while (root.compareTo(divisor)>=1) {
    BigInteger reminder = mprime.remainder(divisor);
    if (reminder.compareTo( BigInteger.valueOf(0)) == 0) {
    primechecker = false;
    divisor =mprime;
    }
    else { divisor=divisor.add(BigInteger.valueOf(1));
    }
    }
    if (primechecker) {
    columnmaker =columnmaker + mprime + "| |";
    counter-=1;
    }
    prime =prime.multiply(BigInteger.valueOf(2));
    mprime = prime.add(BigInteger.valueOf(-1));
    }
    System.out.println(columnmaker);
    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,956
    Rep Power
    8

    Default Re: finish the code please

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: finish the code please

    grjmmr, please go through the Forum Rules, particularly the third paragraph.

    Also go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    fam2315 is offline Member
    Join Date
    Feb 2011
    Posts
    78
    Rep Power
    0

    Default Re: finish the code please

    BTW, if you recognize who wrote this please leave a name so I can give credit during my speach
    That's rich.

    What do you think is wrong with the program?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: finish the code please

    Quote Originally Posted by grjmmr View Post
    BTW, if you recognize who wrote this please leave a name so I can give credit during my speach.
    Why don't you just credit the blog from where you lifted it?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 9
    Last Post: 12-17-2012, 11:29 PM
  2. Not sure hot to finish this Java code..
    By john_java in forum New To Java
    Replies: 8
    Last Post: 03-29-2012, 11:37 PM
  3. Replies: 8
    Last Post: 06-06-2010, 03:10 PM
  4. how to finish this?
    By xpandaxlover in forum New To Java
    Replies: 2
    Last Post: 04-09-2010, 07:43 PM
  5. how to finish this?
    By xpandaxlover in forum New To Java
    Replies: 1
    Last Post: 04-09-2010, 07:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •