how to get prime number in java

Solutions on MaxInterview for how to get prime number in java by the best coders in the world

showing results for - "how to get prime number in java"
Thiago
26 Feb 2016
1public class Prime {
2    public static void main(String[] args) {
3
4        int num = 29;
5        boolean flag = false;
6        for(int i = 2; i <= num/2; ++i){
7            if(num % i == 0){
8                flag = true;
9                break;
10            }
11        }
12
13        if (!flag)
14            System.out.println(num + " is a prime number.");
15        else
16            System.out.println(num + " is not a prime number.");
17}}
queries leading to this page
prime numbers method javajava prime number programprime number javawap to find prime number in javajava program to find prime numbershow to write code for prime numbers in javajava check for prime numberfind prime number in javaprime numbershow to identify prime number javajava prime numberprime number java codewrite a java program 2c which will take a number variable and check whether the number is prime or not java program to check prime numberprime or not in javajava program to determine prime numberjava program to prime numbercode for prime number in javahow to find prime number in javahow to check for prime in javajava check fi number is a prime prime number finder javacode for prime no in javaprime numbers program in javawrite a java program to check whether given number is prime or not prim number javacheck for prime numbers in javajava program to check whether a number is prime or compositehow to get prime number in javajava code for prime numberjava prime numberswrite a program in java to find out if a number is prime in javajava find prime numberswhat are prime numbersjava code to finde prime numberhow is prime number method in javacheck if a number is prime javahow to write prime number by using method and function in javawrite a program to check if a given number is prime or not how to find prime in javaprime number program in javaprime number code in javacheck prime number in javajava get write prime numbersprime numbers javahow to print prime numbers in javacheck prime number javaprime number or not in javaprime number code javaprime number in java shortest codehow to check if a number is prime in javalogic of prime number in javafunction to find prime number javaprime numbers in javahow to find prime numbers in javais prime number javais a number prime javasimple java program for prime numberprogram to check prime number in javajava code to get prime numbersprime number checker javajava program to check prime number or nothow to check if a number is prime in java inputprime number algorithm javahow to find a prime number in javajava program for prime numberprime number program javaprime nuber in javaprime number java programprime logic in javaprime and non prime javaprime no in javawrite a program to check the prime number in javais prime function javaprime no program in javahow to find out if a number is prime in javajava code to check prime numberjava program to find a prime numberjava program to find prime numberjava code to calculate prime numberall prime numbers javaprime number in javaprime in java prime in javajava all prime numberhow to write in java prime numbersprime code in javajava program to check prime number input by command line argumentshow to get prime number in java