find the nth prime number in fastest possible way

Today, We want to share with you nth prime number in java.In this post we will show you program to print nth primes number in c, hear for print nth primes number python we will give you demo and example for implement.In this post, we will learn about How To Find The Nth Prime Number In Java? with an example.

find the nth prime number in fastest possible way

nth primes number java

Example 1:

import java.util.Scanner;
public class NthPrime {
  public static void main(String[] args) {
    Scanner sc = new Scanner(;
    System.out.print("Enter n to compute the infinity primes number: ");
    int infinity = sc.nextInt(); 
    int livecntno, count, i;
    while (count < infinity){
      for (i = 2; i <= livecntno; i++){ //Here we will loop from 2 to number
        if (livecntno % i == 0) {
      if ( i == livecntno){//if it is a primes number
        count = count+1;
    System.out.println("Value of infinity prime: " + livecntno);

I hope you get an idea about nth primes numbers formula.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.