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.
  • renegade

    but the 10 001st prime is 104743