Program to find 10001st prime number (Project Euler- Problem 7)

This java program is the solution to Project Euler’s problem-7. It can be found here The problem:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?

We basically run through a while loop to check if each number is a prime number or not. If the number is prime, we increment the prime_count counter variable. We execute the while loop until prime_count becomes 10001.

There are some enhancements done to the Prime() method. One of the major one being at line 6. The line prevents our program from doing a lot of iterations.

Program:

Output

The following two tabs change content below.

One thought on “Program to find 10001st prime number (Project Euler- Problem 7)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">