Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help in Java, Prime Numbers

    I need to make a program in java which inputs a number, and finds the prime number AFTER it. It has to do it as quick as possible, and use the long start = System.currentTimeMillis(); to do the timing. I have no idea where to start, tried a few things, none of which will work. Any ideas/help?

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    This homework? try posting what you've done and someone can point you in the right direction...

  • #3
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not homework, extra practice. I have no idea where to begin. I can kinda check if a number is prime, but it'll take too long once it gets high numbers, checkng every number...

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I once made a program when I was learning java that would accept a number from the user, and then print all the prime numbers after it, I'm not sure if it'd be of any help to you...let me know, otherwise i'm sure some of the java guys can surely help you out

  • #5
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anything would help at this point...
    I now have a prob though, how do I store 90,000,000,000,000,000 into a number...
    Last edited by odie5533; 11-25-2004 at 06:12 AM.

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Here's what you'll need for that huge number. [http://java.sun.com/j2se/1.4.2/docs/...igInteger.html]

  • #7
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't understand how BigInteger works, can you show me an example, of like the BigInteger being multiplied by 3?

  • #8
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I'm pretty sure that you just replace "int" with BigInteger as follows.
    Code:
    BigInteger bigNumber = 1,000,000,000;


  •  

    Posting Permissions

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