# Find nth prime number in java

In this post, we will see how to find nth Prime number in java.

## What is prime number

Prime number is a number that is greater than 1 and divided by 1 or itself.
For example: 5, 7, 13, 23

We have already seen how to check if number is prime or not. We will use same method to find nth prime number in java.

## Nth prime number in java

Here are steps to find nth prime number in java.

• Take value of `n` from user using Scanner class.
• Intialize a variable `count`. It will keep track of number of prime number processed so far.
• Intialize a variable `i`. It will keep track of current number.
• Iterate over while loop until `count ! = n`
• Increment `i` by 2 as even numbers are not prime
• Check if number is prime. If number is prime then increment `count` by 1.
• Return `i` which is nth prime number.

Output:

Enter the value of n
24
Nth Prime Number is: 89

That’s all about how to find nth prime number in java.

import_contacts

### You may also like: ## Related Posts

• 08 May

### Star Pattern programs in Java

Learn about how to print different star pattern in java.

• 17 April

### Convert Roman Number to Integer in Java

Learn about how to convert Roman number to Integer in java.

• 30 December

### Rock Paper Scissors Game in Java

Learn about how to implement Rock Paper Scissors game in java.

• 25 December

### Find automorphic number in java

Learn about how to find automorphic number in java using different methods

• 06 October

### Implement distance formula in java

In this post, we will see how to implement distance formula between two points in java. Formula to find distance between two points ( x1, y1) and (x2 , y2) is d= sqrt( (x2-x1)^2+ (y2 – y1)^2) Here is simple program to calculate distance between two points in java. [crayon-616c310c3224f665944143/] Here we have used math.sqrt […]

• 06 October

### Convert decimal to binary in java

Table of ContentsUsing Integer.toBinaryString() methodUsing iterative array approachUsing stack In this post, we will see how to convert decimal to binary in java. There are lot of ways to convert decimal to binary in java.Let’s explore them one by one. Using Integer.toBinaryString() method You can simply use inbuilt Integer.toBinaryString() method to convert a decimal [crayon-616c310c323e6380430848/] […]

## Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.