how to find the nth prime number in java

how to find the nth prime number in java

strong texthow to find the nth prime number in java

View Answers

November 18, 2011 at 4:01 PM

class FindNthRrime{

    public static void main(String a[]) {
      find(7);
    }
      static void find(int n){
        int i=0,count=2;
        if(n==1)
        {
            System.out.println("1st prime =2");
            return;
        }
        if(n==2)
        {
            System.out.println("2nd prime =3");
            return;
        }

        while(true)
        {
            for(int j=2;j<=i/2;j++){
            if(i%j==0)
            break;
            else if(j==i/2)
            {
            count++;
            }
        }
        if(count==n)
        {
        System.out.println(n+"th prime ="+i);
        break;
        }
        i++;
        }
    }
    }









Related Tutorials/Questions & Answers:
Find prime factors of non prime number
Find prime factors of non prime number In this section, you will learn how to find the prime factors of the non prime number. Here we have prompted the user... displayed a simple message and if the number is not a prime number we have find all
Find out the prime number
Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop' statement and given the required condition for a prime number. As we know
Advertisements
prime number - Java Beginners
prime number  i want to write a code in java that picks prime numbers from an existing list regardless how long the list is, it should then select non prime numbers when prime numbers are finished   Hi Friend, Try
prime number - Java Beginners
prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect. if the number is not a prime number then print the prime factors of the number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  write a java program for prime number
Prime Number in Java
Prime Number in Java       This Java programming tutorial will be read how to get prime number. First of all we will define a class "Prime Number". Java I/O package
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime... a class with class name prime number, using switch case, in case first using two
prime number
prime number  HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader
prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber... is Prime!"); } else{ System.out.println("Number
prime number
prime number  To check a number entered by user is prime
Prime Number in Java
Prime Number in Java In this Java tutorial , you will learn how to write a Java program to get prime numbers between 1 to the desired number. To start... the bytes.ADS_TO_REPLACE_1 In this example of writing java program to get prime
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other... of Prime Number program in Java: package Tutorial; public class PrimeNumber
prime number question - Java Beginners
prime number question  For the question located here: http://www.roseindia.net/answers/viewanswers/5778.html How do you make it so that the user has to input the two numbers and it displays the prime numbers within the range
how to find largest number? - Java Interview Questions
how to find largest number?  this is my java coding: import...); } } i don't know how to add code to find the largest number.. please help...; yup yup.. i want to know how to find the greatest number that enter
prime number
prime number  could u pls help me out in finding whether a number is a prime number or not?   import java.util.*; class CheckPrimeNumber... is Prime!"); } else{ System.out.println("Number
prime number
prime number  to check wethere given number is prime or not?  ... is Prime!"); } else{ System.out.println("Number... { static boolean isPrime(int number){ boolean isPrime=false; int
Prime Number in Java
Prime Number in Java       This Java programming tutorial, we will be read how to get prime number.... If number is divided by any number that means it is not prime otherwise prime
How can i read a file from nth line onwards in java
How can i read a file from nth line onwards in java  Hi, I need to read a file content from its nth line onwards till end. How can i implement it in java. Regards, Chinnu
Java find prime numbers without using break statement
Java find prime numbers without using break statement In this tutorial, you will learn how to find the prime numbers without using break statement. You all...(number); } } } Output: Prime Numbers between 1 and 50: 2 3 5 7 11 13
ModuleNotFoundError: No module named 'Is_this_a_prime_number'
: No module named 'Is_this_a_prime_number' How to remove the ModuleNotFoundError: No module named 'Is_this_a_prime_number' error? Thanks   Hi...ModuleNotFoundError: No module named 'Is_this_a_prime_number'  Hi
Prime And Fibonacci Number Finder
Prime And Fibonacci Number Finder In this section, you will learn how to find the prime numbers which are generated in the fibonacci series. To compute... number is prime or not? If it is prime Number, the number will get displayed
ModuleNotFoundError: No module named 'find_a_prime'
'find_a_prime' How to remove the ModuleNotFoundError: No module named 'find_a_prime' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'find_a_prime'  Hi, My Python
how to find square and cube of five number
how to find square and cube of five number  how to find square and cube of five number   Hi Friend, Try the following code:ADS_TO_REPLACE_1 <html> <script> document.writeln("Square of 5 numbers:<br>
how to display nth greatest salary - SQL
how to display nth greatest salary  how to display nth greatest salary
ModuleNotFoundError: No module named 'prime_number_checker'
: No module named 'prime_number_checker' How to remove the ModuleNotFoundError: No module named 'prime_number_checker' error? Thanks   Hi...ModuleNotFoundError: No module named 'prime_number_checker'  Hi
ModuleNotFoundError: No module named 'get-prime-number'
named 'get-prime-number' How to remove the ModuleNotFoundError: No module named 'get-prime-number' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'get-prime-number'  Hi, My
compute nth root - Java Beginners
compute nth root  write a program that computes the nth root of a number. given a real number X greater than 1 and less than -1 and given an integer Y, compute the nth root Z such that Z*Z*Z*Z*Z*Z*Z...(Y times)..Z*Z=X, or Z^y=X
How do I find out the number of parameters passed into function9. ?
How do I find out the number of parameters passed into function9. ?  How do I find out the number of parameters passed into function9
How can we find the number of rows in a result set using PHP?
How can we find the number of rows in a result set using PHP?   How can we find the number of rows in a result set using PHP
Find Numbers which are palindrome and prime
Find Numbers which are palindrome and prime In this section, you will learn how to find the numbers from 1 to 500 which are palindrome and prime. To compute.... The Iterator class iterates the ArrayList and check whether number is prime
prime numbers - Java Beginners
prime numbers  Write a java program to find the prime numbers between n and m
How to format number in Java?
How to format number in Java?  Hi, What is the best way to format a number in Java? How to format number in Java? Thanks   Hi, To format number in Java you can use the class java.text.NumberFormat. Here is simple
find the largest number enter by user - Java Interview Questions
find the largest number enter by user  sorry for not stating clearly my question. i want to know how to find the largest number enter by user. thanks. this is my java coding: import java.util.Scanner; import java.io.
Find Twin Primes Number using Java
Find Twin Primes Number using Java In this section, you will learn how find... the 'for loop' statement and set the required condition for a prime number... by 1 and the number itself. Here we are going to find twin primes. Twin Primes
A program to find the sum of odd number
A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... the console. Now here is the simple example which will help you to find the sum of odd
how to find the roots of polynomial equation of 'n'th degree in java
how to find the roots of polynomial equation of 'n'th degree in java  i am new to java field and i wanted to find the roots of nth degree polynomial equation pls help me. thanks
Find Second Largest Number from an Array
Find Second Largest Number from an Array This section illustrates you how to find the second largest number from an array. For this purpose, we have allowed... among them. Pulls the largest number out from the array and again check
Pick Prime Numbers from the ArrayList
integer values in the arraylist and from the arraylist we have to find the prime and non prime numbers separately. Here is the code: import java.util....Pick Prime Numbers from the ArrayList Programmers mostly used ArrayList
How to format number in Java?
Learn about the code of formatting the number in Java This tutorial explains you how to format the number in Java. There are number of situations where we...: D:\examples\roseindia.net\corejava>java NumberFormatting Number formatting
how to find [count the number of integers whose value is less than the average value of the integers]
how to find [count the number of integers whose value is less than the average value of the integers]  Construct an algorithm that will prompt... amount to the screen integers from an operator at a terminal, and count the number
Prime numbers in Java between 1 and 100
Prime numbers in Java between 1 and 100  Hi, How to display prime numbers in java between 1 and 100? Thanks   Hi, Prime numbers are the number which is divisible by itself and 1. I have provide you Java program
prime pal - Java Beginners
prime pal  1) WAP to print all prime-palindrome number range between 1-500 2) WAP to print all prime-Fibonacci number range between 1-500   Hi Friend, 1)Prime and Palindrome: import java.util.
How to find hashtable size in Java?
How to find hashtable size in Java?  Hi, What is the code for Hashtable in Java? How to find hashtable size in Java? Give me the easy code. Thanks
How to round a number to n decimal places in Java
How to round a number to n decimal places in Java  How to round a number to n decimal places in Java
Write a query to find the total number of rows in a table
Write a query to find the total number of rows in a table  Write a query to find the total number of rows in a table?   Hi, Here is the answer,ADS_TO_REPLACE_1 we can find the total number of rows in a table using
how to create month wise serial number in java?
how to create month wise serial number in java?  Ex: For 1)January-serial number is 1/001,1/002,1/003 etc
find factorial of any number using recursion
find factorial of any number using recursion  error in 14 line ; expected int rec( int a) ^ how to resolve this.please correct the code. import...)); System.out.println(?enter number?); int x=Integer.parseInt(br.readLine()); int result

Ads