print prime numbers in java

Solutions on MaxInterview for print prime numbers in java by the best coders in the world

showing results for - "print prime numbers in java"
Katya
10 Jul 2020
1// Java program to print prime numbers in a given range
2public class PrimeNumberRangeDemo 
3{
4   public static void main(String[] args) 
5   {
6      int lowerRange = 10, higherRange = 50;  
7      while(lowerRange < higherRange) 
8      {
9         boolean flag = false;
10         for(int a = 2; a <= lowerRange / 2; ++a) 
11         {
12            if(lowerRange % a == 0)
13            {
14               flag = true;
15               break;
16            }
17         }
18         if(!flag && lowerRange != 0 && lowerRange != 1)
19             System.out.print(lowerRange + " ");
20         ++lowerRange;
21      }
22   }
23}
Santiago
10 Mar 2018
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}}
Inès
22 Jan 2017
1// Java program to print prime numbers upto n
2import java.util.Scanner;
3public class PrimeNumberUptoN
4{
5   public static void main(String[] args)
6   {
7      Scanner sc = new Scanner(System.in);
8      int a = 0;
9      int n = 0;
10      String strPrime = "";
11      System.out.println("Please enter the value of n: ");
12      int number = sc.nextInt();
13      for(a = 1; a <= number; a++)
14      {
15         int counter = 0;
16         for(n = a; n >= 1; n--)
17         {
18            if(a % n == 0)
19            {
20               counter = counter + 1;
21            }
22         }
23         if(counter == 2)
24         {
25            strPrime = strPrime + a + " ";
26         }
27      }
28      System.out.println("prime numbers upto n are: ");
29      System.out.println(strPrime);
30      sc.close();
31   }
32}
Klara
06 Feb 2017
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}}
18Source:www.progra
19
Nael
13 Mar 2020
1import java.util.Scanner;
2 
3public class PrimeNumberChecker {
4    public static void main(String[] args) {
5        System.out.println("Enter a number to check Prime or Not");
6        Scanner scanner = new Scanner(System.in);
7        int number = scanner.nextInt();
8        int i = 2, count = 0;
9        while (i <= number / 2) {
10            if (number % i == 0) {
11                count++;
12                break;
13            }
14            i++;
15        }
16        if (count == 0) {
17            System.out.println(number + " is prime number");
18        } else {
19            System.out.println(number + " is not a prime number");
20        }
21    }
22}
Paula
09 Jan 2017
1import java.util.ArrayList;
2import java.util.List;
3import java.util.Scanner;
4 
5public class PrimeNumberChecker3 {
6 
7    public static List<Integer> generatePrimeInRange(int startRange, int endRange) {
8        if (startRange >= endRange) {
9            System.out.println("endRange must be greater then startRange");
10            System.exit(0);
11        }
12        List<Integer> primeList = new ArrayList<>();
13        while (startRange <= endRange) {
14            int i = 2, count = 0;
15            while (i <= startRange / 2) {
16                if (startRange % i == 0) {
17                    count++;
18                    break;
19                }
20                i++;
21 
22            }
23            if (count == 0) {
24                primeList.add(startRange);
25            }
26            startRange++;
27        }
28        return primeList;
29    }
30 
31    public static void main(String[] args) {
32        System.out.println("Enter a number range to generate prime numbers in between");
33        Scanner scanner = new Scanner(System.in);
34        int number1 = scanner.nextInt();
35        int number2 = scanner.nextInt();
36        List<Integer> primeNumbers = generatePrimeInRange(number1, number2);
37        System.out.println("Prime Numbers are");
38        System.out.println(primeNumbers);
39 
40    }
41}
queries leading to this page
java check if a number is primehow to find the prime number in javacalculate the t prime number program in javawrite a program 2c which prints all the prime numbers in the range of two given numbers m and n in javaprimeng javacode for prime number javahow to check prime or not in javajava prime number using whilleprime numbers java functionwrite a java program to determine whether a number is or is not a prime numberwhat is the logic of prime number in javaexplain prime number logic in javajava is 0 prime numberjava is number a prime numberall pali prime number in javaprime number algorithm javaprogram to print range of prime numbers in javajava find prime numbers in rangehow to check if a number is prime in javahow to calculate prime number in given range in javaallintitle 3ajava program to print prime numbers upto njava find prime numbers fromall prime numbers in javacheck if prime javaprime number program in java using functionfind a prime number javaprime function javaprime number in javaprime numbers meaningjava code to display count of prime numbers in a rangeprime number in range javaprime number math program javan prime number or not in javahow to find prie in javacheck number is prime or not in javajava get write prime numbershow to check if number is pime javaprime numbers in javacheck prime javaprime numbers below a given number javaprime java rocresiajava get primesfind the prime number java codefind prime number or not in javajava prime number usingjava find prime numbers funktionjava prime numberjava program to get prime numbers or nothow to get prime nu 2cbers javajava method to check for prime numbershow to check for prime in javahow to check prime no in javawhat does primes 2b 3d mean in javahow to write a prime number program in javaprime nujmber in javahow to find the number is prime or not javacalculate prime number in javawrite a java program for prime number prime numbers javafinding the prime number in javahow to check if a number is a prime in java in 1 linehow many ways to create prime number in javawrite a java programme to print a number is prime or notallintitle 3ajava program to print prime numbers in a given rangewrite a java program to check if a given number is prime or nota program to check if a number is prime javawrite a program to check the prime number in javaprime code in javacalculate prime numbers in javaprime number finding in java prime in javaprime numbers code in javahow to find a number is prime or not in javaoolean prime in javahow to find prime numbers using javajava program to print all prime numbers till n to check if a number is prime javaprogram to find the prime number in a given range javaprint n prime numbers in javahow to determine if a number is prime javaa number is prime or not in javaprime checker program javajava prime noprime nuber in javafind prime number javafind primes in javajava code to print prime numbers in given rangegenerate prime numbers javatake n as input print all prime numbers from 2 to n javabest prime number program in javahow to check for a prime number in javaprime number calculator javacheck prime java while loohow to check if number prime in javaprime number in a range in javashow is prime number method in javahow to find prime numbers in javaprime numbers using javacheck if number is prime in javanumber of prime or not program in javacode for prime no in javaprime number logic javajava program to check given number is prime or notcheck prime number in javapimenumber javaprime numbers method javawrite a java program to check whether given number is prime or not optimal way to check wheter given number is prime or not in javawrite a java program to check prime numberprime number java program simplejava program to find prime numbersjava code to check for a prime numberto print all the prime number in javaprint prime numbers in javajava code to finde prime numberjava integer prime numberhow to get prime number in javahow to check prime number in javato print the prime numbers in javaprime no javajava find prime numberprime number exmaple in javatest for prime number javaho to find the amount of prime number in javagetting a set of prime numbers javajava program to check prime number input by command line argumentsjava find all prime numbersjava program to check prime numberprimes javaprint all the prime number between range javajava how to get prime or compositejava code for prime number checkinghow to find prime and nonprime numbers in javabest way to print prime numbers in javahow to check for prime number in javahow to find a prime number in javaprime number using javahow to check prime numbers in javarange of prime numbers in javacheck if a number is a prime number javacheck is prime javaprime no in javahow to find prime numbers javaprime number in java user inputhow to determine if a number is prime in javaprint prime numbers using javajava all prime numberprint prime number in java efficient waywap to print first n prime numbers in javahow to check prime in string javafind if number is prime javacode to find prime number in javaprime inbuilt function in javahow to check the no is prime or not in javacheck prime number in a given range javaprime number coding in javajava code for prime number checking from useris prime method java which classwhat are prime numberscode to check if a number is prime in javaprime or not in javadoes java a built in prime number methodis prime javahow to check if a number is prime or composite in javajava program to print range of prime numbers upto given numberfor printing the series of prime numbers javaprim number javacan void check if a number is prime in java print prime numbers in java geeksforgeeksjava program to find prime number using methodprime not prime in javatest if a number is prime javacheck for prime numbers javais prime function javahow to write code for prime numbers in javaprint prime number in javajava is primejava rmi prime number programprimes numbersto find prime number in java in set of elementswrite a program to find out if a number is prime javahow to find number of prime numbers using javaprime detecting javajava program to print prime numbers upto ncheck whether prime number java programprime number code javajava prime number programjava program finding prime numbersfind prime number in java using for loopchecking if a number is prime javaallintitle 3ajava program to print prime numbers from 2 to njava how to check if a number is primeprogram to check for prime numbers in javawrite a program that takes a range of number as input and outputs the prime numbers in that range in javawhy 4 is prime number in javawhat is prime number javajava primeprogram to find prime numbers javafind prime number using javajava check for prime numbersimple prime number program in javanumber is prime or not program javawrite a program to check if a given number is prime or not in javaprime logic javajava prime number allprime numbers formula javaprime number in java printfind prime number in java using while how to solve prime numbers javacheck for prime number javajava program for prime numbers till nfind prime numbers in a range in javajava program to find a number is prime or notlist of prime numbers in given range in javajava program to print prime numbers or same numberprime i javafind prime number in java avapointhow to find if a number is prime in javajava prime checkprime numbers java programjava program to check prime number or notwrite a program to find a given number is prime number or not javacalculating prime numbers javaprime number algorithm in javaprime no code in javahow to find number of prime numbers up to to n javaprime number program in java using for loopprint prime number in range javawhat are the prime numbersjava find prime number methodjava program to check whether number is prime or notjava print n prime numbershow to calculate prime number javahow to find prime and composite numbers in javafind the prime number in a range in javafind prime number in javaprogramming with java prime simple java program for prime numberjava is prime functionnumber is prime or not in javahow to find prime in javacheck prime number in java using for loopget prime number in javaprint prime numbers with exponents using javafind if a number is prime javahow to check if numbers is prime in java inputchecking prime number in javahow to write prime number by using method and function in javawhat are prime numbers in javaprime numbers in a range javaprime number in rangein javaprime number check javahow to solve for prime number javawrite a program to check whether a number is prime or not javaprint only prime numbers in javaprime number or not javawrite a program to find the number of prime numbers in javawrite a program to check whether a given number is a prime number or not in javaprime number formula javaget prime numbers javaprint prime numbers from 1 to 100 in java with explanationprime or not in java in javaprime number code in jvaawap to input any number then check whether it special prime no or notcalculate prime number in java using functionprime finder javaprime number checker javaprogram to check prime number in java different wayprime n0 in javareturn the n prime number in javajava prime number or notprime no program in javaprime numbers upto n in javaprime number in java using 2fhow to print prime numbers in javatesting for prime number in javaprogram to prime number in javafind and print n prime numbers in javahow to get a prime number in javacount of prime numbers java programwrite a program to check if a number is a prime number or not javawrite a program in java to find out if a number is prime in javahow to find prime number series in javaprime built in function in javawork out prime number in javawrite a program in java to find out if a number is prime in java 3fhow to prime numbers in javawrite a java program to display all prime numberfind prime numbers javajava check if a nymber is primejava program on prime numberjava program to find number of prime numbers in a rangeto print the prime numbers in javajava program to find the given number is prime or notprime number or not program in javalogic for prime number in javacalculate check prime number in java using functionprime number program in javanon prime number java programidentify prime in javajava prime number checkerhow to get prime number in javais prime number in java optimalprime function in javaprime of primes program in javajava check prime numberprime number program in java using while loopjava code for prime numberjava check if number is primeprogram to print the prime number in the range in javaprime number java rangeprint all prime numbers in a given range in javaprime number java codehow to figure out prime numbers javaprime number java logicprime number loop javaprime numbers detection program in javaprogram to count prime numbers in javaprime number program in java print from 1 to 50 a prime number in javawrite a java program to find whether a number is primeprime detecting java from 1 to nfind prime number by 2 input elements javaprint 1 to n prime numbers in javahow to code a program that displays prime numbers in javahow to check given number is prime or not in javaprime number logic in javacheck prime and print prime in javaprime number program javajava program to print prime numbers in a given rangehow to find if a number is prime number or not in javacheck for prime javaprime num javacode to determine if number is prime number or not in javajava prime number prime number utility i javajava program to find a prime numberprint all prime numbers from 1 to n in javawhat is a prime no javaprime numbers finding in given number range using javaprime numbers finding in given number range using java in shortest timeprogram to find number of prime numbers in a range javawhat is int prime number in javadetermine prime numbers javalogic to find prime numbers from specific range javajava program to print highest prime numberprime numbers definitionhow to prime number in javaprime number in javaprime operator javahow to find the number of primes is a number javajava program for prime numberprint prime numbers upto n in javaprint prime numbers up to a given number in javajava prime packagejava prime or compositeprime number function in javacheck prime in javadisplay prime number javahow to find prime numbers with help of and operator in javaif a number is prime number or not entered by the user in javamethod to get prime numbers in javawrite a java program 2c which will take a number variable and check whether the number is prime or not write a program to print all prime numbers up to n javajava orime numverprime numbers java program for picking prime numbers in a given rangetest prime number javais prime in java functionbest way to find prime numbers in javajava fastest way to get prime numbersprime number java 8how to determine a prime number in javajava prime number functioncalculate prime numbers javawrite a program to print prime numbers in javaprint n prime number in javajava program to print all prime numbers in a given rangewrite a java program to print all prime numbers in the interval 5ba 2cb 5d 28a and b 2c both inclusive 29 check for prime number in javaprime number in java programmizhow to check if number prime in javaprime and composite numbers java codewhat is the login for prime numbers to write in javahow to calculate prime no in javasimplest prime number program javajava prime numberscheck if the entered no is a prime no or not using javawrite a program in java to print all prime numbers between n and m how to print a prime number in javajava programe to decide prime numberprime method in javaprime nmber in javaprime number program in java within rangehow is prime number method in javajava find a prime numberjava code to find prime numberprint prime number in given range in javatotal prime in java in given rangewrite a java program to check prime number by entering any numberhow to check all prime number in javaprime number check in java38 finding prime numbers in a given range javajava code prime numberprogram to find prime number in javahow to print prime numbers and sum of the prime numbers in javais this number prime javaprint number of prime number user value in javaprime no logic in javafind prime number in java methodjava program to find prime numbers in a given rangehow to check prime number with loop javastring function in java to check a number is priem or notjava primary numberfind prime number by 2 elements javatake n as input print all prime numbers from 2 to n in javafinding prime numbers in javaprimary number code javahow to check for prime numbers javaprogram to find prime numbers in javaall prime numbers javaprime numbers from javahow to find if number is prim javawrite a java program to check number is prime or notprogram to calculates all prime numbers in given range and store them in an array in javaprint range of prime numbers in javahow prime number in javaprime or not javaprime and non prime javajava program to determine prime numberknow prime number in javafinding prime number in javaprint a single integer e2 80 94 the answer to the problem without leading zeroes 2c or 22 1 22 28without the quotes 29 2c if the number that meets the problem condition does not exist prime number code in javaprime logic in javahow to check for prime numbers in javajava program to check whether a number is prime or compositehow to write in java prime numbersjava program prime numberfinding prime numbers in a given range javajava prime number with for loopprime number condition javalist of prime number program in javaprimes number javaprime numbr in javaa program in java to print prime numbers from 1 to n 28user input 29find prime number in java 8java program for prime numbershow to print prime numbers and sum of the numbers in javais prime java methodprime number in java shortest codecheck if number is not prime javadetermine prime number javawriting a java function to count the prime numbers in given rangeprime no program in java user inputfind prime numbers from n javajava program to print prime numbers from 2 to njava oop prime finderfunction to find prime number javaprime number finder javagiven number is prime or not in javajava coding to find prime numberjava program prime numbershow to add prime numbers in javaprime javahow to find prime number javaidentify a prime number javajava code for finding prime numbersjava code to determine prime numbers in a rangehow to find the prime numbers in java methodprime numbers condition in javais prime number javadefine prime numbersprime number program in java using scannerjava to find prime numberlogic of prime number in javajava isprime testwhat is prime number in javato identify a prime number javahow to find prime numbers in a range javaprime no or not in javajava program to check prime number using for loopprint prime number javafind prime no in javaprime integer javajava program to find prime numberprime numbers program in javajava is prime numberfinding prime numbers for given number in javajava if number is primeprime number identifier java functionhow to find prime no upto n number in javafind prime number program in javajava print all prime numbers that can be made form a numbert prime in javaprime number testing in javaprime number function javaprogram to find prime in javajava prime or notcode to print all prime numbers up to 100 javaprime number definitionprint prime numbers javaprime numbers def javawrite a java program to check a number is prime or notis there a class in java with prime numbersprogram to find prime number upto n in java with lowest complexityprime numbers algorithm in javajava program to check whether a number is prime or nothow to check if number is prime javais a number prime javafind prime number in range javaprime number printing within a given range in javajava calculate prime numberpriem method in javacheck whether the given nos are relatively prime or not in javaprime no in javaprint prime number program in javahow to find primes in javawrite a program to print prime number in javaprogram for prime no in javaprint prime numbers from 1 to n in javafind prime in javaprint prime numbers from given number in javaprime no javajava program to print 100 prime numbersjava code program prime numbersprime number test javaprogram to find a prime number in javaprogram prime number in java11 write a program to check the prime number in javajava prime programcheck if a number is prime or not for binary value in javawrite a program to check if a given number is prime or not java program to print prime numbers in a given range using while loopprime in javanumber prime or not in javacondition for prime number in javahow to check if number prime in javacheck if number is prime javafind all prime numbers javacheck no is prime or not javaprime no s in javajava prime number checkwhat is prime numbersjava program to print prime numbersjava code to find prime numberscode for prime number in javacode for prime numbers javaprime numbers in a given range in javawap to check prime number using method in javafind prime no code in javaprime numbers javaprime number java programhow to calculate prime number in javajava program to print prime numbers for given rangecheck prime number javahow to find prime numbers in a given range in javahighest prime number code in javaprogram for prime number in javawap to find prime number in javajava primeis prime in javajava program to check whether the number is prime or notprime number or not in javaprogram of prime number in javahow to find a prime javajava code to get prime numbersprime numbers upto a given number in javaprime number program in java programizprime no logic in javajava code to calculate prime numbercheck if a number is prime or not javajava program to prime numberfind a number relaitively prime with other number javaprinting prime numbers in javadetermining if a number is prime javaprogram to find prime number upto n in java with lrecursionwriting a prime function javaif its a prime number javaprime no from given range program in javaprime number progra javahow to calculate prime numbets in javaread an array of integers in your overloaded main method and determine how many numbers are prime numbers and composite numbers prime numbers in range in javahow to check prime number javaprogram to check for prime number in javawrite a java program to check whether the number is prime or notget the prime number in range in javaprint prime number code javahow to create primes in javajava program to print all prime numbers in an intervalprime no in javafind whether a number is prime or not in javaprime method javaprime number javaprime number program in java using user inputfunction prime number logic in javahow to find out if a number is prime in javasimple prime number logic in javaprime number print in javahow to identify prime number javajava program print prime numbers upto nprime logic in javaprime numbers in java gfgcreate a class that has a method to find out whether a given number is prime or not 3fcheck for prime numbers in javajava how to find prime numbersjava code for prime number or nptis prime method javacheck number is prime or not in java optiimizedprime number in least time in javaprime number find in javajava find prime numbersprint first n prime numbers in javajava program to get prime numbersprimenumbers javafind prime numbers in javaprime number code in javajava to check if its a prime nuumber or not scanner methodprime number of anumber in javafind prime number by 2 input integrers javajava program to check prime number using methodscheck if a number is prime javafinding prime number javajava to print all prime numbers smaller than njava code prime number for loophow to check if a number is prime in java inputhow to find prime numbers programm in javaprogram to check prime number in javaprime numbers till n in javaprint prime javasquare numbers and prime numbers javaprime numbers programs in javahow to check whether a number is prime or not in javaprime number icode in javaprint prime number using javacheck if prime number javais prime numer javajava program to print prime numbers from m to n using for loopprime number in range in javaprime numbers formula in javaprogram to print prime numbers in javajava finding prime numbershow to find prime number in javajava how to check if a number is a prime numberfinding prime number javacode of prime number in javaprint the prime number from 1 to n in javaprime number in java gfg practicejava program to find primeto check prime number in javajava print prime numberscheck whether the number is prime or not in javahow to print prime number in given range in javajava program to find prie numberjava method for prime numbershow to determine prime numbers in javaallintitlle 3ajava program to print prime numbers from 2 to njava check fi number is a prime range of prime number program in javawrite a java program to find prime numberhow to find prime numbers with javaprimenumber finder javajava code to check prime numberprime checker javahow do i calculate prime number using javaprime number in java in rangeprint prime numbers in java