java program to print prime numbers in a given range

Solutions on MaxInterview for java program to print prime numbers in a given range by the best coders in the world

showing results for - "java program to print prime numbers in a given range"
Kevin
17 Aug 2017
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}
Giada
12 Jan 2020
1// Java program to print prime numbers from 2 to n
2import java.util.Scanner;
3public class PrimeNumberFrom2Ton
4{
5   public static void main(String[] args) 
6   {
7      int loop, max;
8      System.out.print("Please enter highest (maximum) number: ");
9      Scanner sc = new Scanner(System.in);
10      max = sc.nextInt();
11      for(loop = 2; loop < max; ++loop)
12      {
13         if(findPrime(loop))
14         {
15            System.out.println(loop);
16         }
17      }
18      sc.close();
19   }
20   public static boolean findPrime(int number)
21   {
22      int a;
23      boolean boolPrime = true;
24      for(a = 2; a < number / 2; a++)
25      {
26         if(number%a == 0)
27         {
28            boolPrime = false;
29            break;
30         }
31      }
32      return boolPrime;
33   }
34}
Erica
21 Jul 2020
1Now let’s see print first 10 prime numbers in java.
2
3public class FirstTenPrimeNumbers
4{
5   public static void main(String[] args) 
6   {
7      int count = 0, number = 0, a = 1, b = 1;  
8      while(number < 10)  
9      {  
10         b = 1;  
11         count = 0;  
12         while(b <= a)  
13         {  
14            if(a%b == 0)  
15                count++;  
16            b++;
17         }  
18         if(count == 2)  
19         {  
20            System.out.printf("%d ", a);  
21            number++;  
22         }  
23         a++;  
24      }
25   }
26}
Marco
23 Feb 2019
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}
Alexa
27 May 2017
1class PrimeNumbers
2{
3   public static void main (String[] args)
4   {		
5       int i =0;
6       int num =0;
7       //Empty String
8       String  primeNumbers = "";
9
10       for (i = 1; i <= 100; i++)         
11       { 		  	  
12          int counter=0; 	  
13          for(num =i; num>=1; num--)
14	  {
15             if(i%num==0)
16	     {
17 		counter = counter + 1;
18	     }
19	  }
20	  if (counter ==2)
21	  {
22	     //Appended the Prime number to the String
23	     primeNumbers = primeNumbers + i + " ";
24	  }	
25       }	
26       System.out.println("Prime numbers from 1 to 100 are :");
27       System.out.println(primeNumbers);
28   }
29}
Felipe
13 Jan 2016
1It will display the prime numbers between 1 and 100.
2
3class PrimeNumbers
4{
5   public static void main (String[] args)
6   {		
7       int i =0;
8       int num =0;
9       //Empty String
10       String  primeNumbers = "";
11
12       for (i = 1; i <= 100; i++)         
13       { 		  	  
14          int counter=0; 	  
15          for(num =i; num>=1; num--)
16	  {
17             if(i%num==0)
18	     {
19 		counter = counter + 1;
20	     }
21	  }
22	  if (counter ==2)
23	  {
24	     //Appended the Prime number to the String
25	     primeNumbers = primeNumbers + i + " ";
26	  }	
27       }	
28       System.out.println("Prime numbers from 1 to 100 are :");
29       System.out.println(primeNumbers);
30   }
31}
queries leading to this page
write a java program to find prime no between 1 to 1000how to get prime number in javajava program to print all prime numbers in a given rangewrite a program that takes a range of number as input and outputs the prime numbers in that range in javaprime number program in java to show two numbersprime number in range javahow to find prime numbers in n in javaprint prime numbers javato print all the prime numbers between 1 to 100 in javacheck for prime number in javajava code to generate prime numbers in sequenceprime number printing within a given range in javajava program to find prime number between 1 and 100is primenumber javaprogram to check prime in javaprint 11 prime number per lineprint n number of prime numbers in javawork out is a number prime in javawrite a program 2c which prints all the prime numbers in the range of two given numbers m and n in javajava method for prime numbersjava get all prime numbersprime numbers between 1 to 100 codeprogram to find the prime number in a given range javaprime number program in java print 1 to 20prime number between 1 100000 loop javahow to find all prime nos from 100 to 200 in javaeasy way to find n prime numbers with array in jvaprinting prime numbers in javaprime numbers javawrite a program to find prime number in a given range in javajava program to print prime numbers 1 to 100how to check number of prime numbers within a range in javajava print n prime numbershow to get prime number javafastest way to find prime numbers in javawrite java code to find prime number between 1 to 100prime numbers between 2 to 100 in javafind prime numbers in range javaprime number condition javaprime number till 10 5e12 javajava is prime o 281 29total number of prime numbers between 1 to 100 java programprogram to find number of prime numbers in a range javaget prime numbers and put into string in javaprime number upto 100 in javaprint prime numbers up to a given number in javaprint 100 prime numbers how to print prime numbers of a number in javajava prime number algorithmprime number 1 to 100 in javahow to print prime number in given range in javaprime numbers from 1 to 100 java code efficientlyprimes between 1 and 100 in javafind prime numbers between start and end javahow to check the no is pirme or not javaprime numbers finding in given number range using java in shortest timejava code to print prime numbers in given rangeallintitle 3ajava program to print prime numbers in a given rangetake n as input print all prime numbers from 2 to n in javalist of prime numbers in java range of prime number program in javaprime numbers 1 100 javaprime number from 1 to 50 in javaprime number program 1 100 in javaprime number in rangein javaprint 1 to n prime numbers in javabest way to check if a number is prime javaprime number program in java between 1 to 100java program to print all prime numbers in an intervalinsert prime number to list and print javahow to determine prime numbers in java1 to 100 prime numbers java programjava how to get the list of prime numbercheck prime numbers 1 100 javaprime number in a range in javajava program to print prime numbers upto ninput prime numbers function in javafunction to display list of prime numbers in javaprimes javaprint prime number in java using single for loopjava program to count prime numbers between 1 and 100java program to find a number is prime or notprime numbers from 1 to 100 in javaprint first n prime numbers in javajava primenumbersjava to print all prime numbers smaller than nprime numbers 1 to 50 program in javaprint prime numbers in javaprime number logic javaget prime number till 10 5e5 jav aprime numbers pt rogram using javaava 5cjava prime numberprime numbers upto given number in javacode to print all prime numbers up to 100 javahow to calculate a prime number in javacreate a program that displays 5 digit prime numbers in javaprime number algorithm in javaprime numbers till 100 codingformula to find prime numbers between 1 and 100 javaprime no in javafastest way to calculate prime or not in javahow to calculate prime number in given range in javaprint prime numbers in java geeksforgeekshow to find out prime numbers in java from 1 to 100prime number from 2 to n in javaprogram to print prime numbers in javafind the prime number in a range in javaall the prime number till 100 javaprint all prime numbers from 1 to n in javahow to calculate n primes number in javbato print the prime numbers in javafind prime numbers between 0 to 100 javaprime number 1 to 50 program in java good algo to find prime number in javajava list of prime numbersprime numbers between 1 and 100 in javawrite a java program to print prime numbersmethod to generate prime number in javaallintitlle 3ajava program to print prime numbers from 2 to nprime number algorithm javaa program in java to print prime numbers from 1 to n 28user input 29list of prime number program in javaprime numbers java 1 to 100java method prime numberprime numbers upto n in javaprogram to generate primes javawrite a program to print prime numbers between 10 and 99 prime no between 1 to 100 in javaprint prime number using javajava prime number functionget list of primes of a number javaprint n prime number in javaallintitle 3ajava program to print prime numbers from 2 to ntotal number of prime numbers between 1 to 1500000 java using single loopfind and print n prime numbers in javajava program to print prime numbers in a given range using while loopprint prime number program in javajava find prime numbers in rangeprime numeber in javabest way to print prime numbers in javajava code to find prime numbers between m and nseries of prime and even numbers in javaget all prime numbers from 1 10000 in javadisplay all prime number and non prime number in javaprime number method javaprint prime numbers between two numbers in javaprime numbers finding in given number range using javato print the prime numbers in javaprimenumbers in javaprime number formula javaprime numbr javalist of prime numbers in java gfgfind the prime numbers from 1 to 100 in javajava program to print all prime numbers between 1 to 100how to print prime numbers in javais there a java package to find prime numbersprint range of prime numbers in javahow to find prime numbers between start and end javaprime numbers from 1 to 50 javaprint out prime numbers javaprint prime numbers using javaget the prime number in range in javafinding primes in javaprime check in javahow to find prime numbers in a range javaprime numbers java algorithmprime number program in java up to 100prime number program in java print from 1 to 50 java program to print all prime numbers till njava program to display all prime numbers from 1 to njava program prime numberprime numbers in range in javajava prime number counterprime number program in java within rangejava program to print prime numbers for given rangewrite a program to generate prime number from 1 to 100 in javafind sum of prime numbers from 1 to 100 in javaprogram to calculates all prime numbers in given range and store them in an array in javafind a prime number java codefind prime number in range javaprime number in javaprogram to find prime number in javagenerate prime numbers in javaprime number program from 1 to 50 in javahow to calculate all the prime numbers in a for loop in javaprint prime numbers from 1 to 100 in javaprime numbers java for loopjava program to display prime numbers between 1 to nprime numbers till n in javaprint all prime numbers from x to 1 in javaprint all the prime numbers from 0 to 1000 in javafor printing the series of prime numbers javaprint all prime numbers upto 100 in javajava all prime numberhow to find prime numbers from 1 to 100 in javaprint all prime numbers from 1 to n javahow to find prime numbers between two numbers in javalist of prime numbers in given range in javaprogram to find prime number upto n in java with lowest complexityget all prime numbers from 1 10000 and add to string in javaprime nuber in javawrite a program to print prime numbers in javaprint prime numbers upto n in java java program for picking prime numbers in a given rangehow to write in java prime numbersjava program to find prime numbers in a given rangefind prime numbers from 1 to 100 in javahow to get the first 50 prime numbers in java using do loophow to find number of prime numbers up to to n javaprint prime number in javaprime javaprime number math program javaprint first 10 numbers prime numbers in javaprime number counter javareturn the n prime number in javafind prime numbers till 1000 javacreate a program that displays prime numbers from 1 to 100 print prime number in java efficient wayjava code to get prime numberslist of prime numbers from 1 to 100 in javaprint prime numbers list javajava calculate prime number 1 1000000 5dcheck prime number in java fastest wayprime numbers in javaprime numbers between 1 to 100 in javajava program to list prime numbersjava program to display prime numbers from 1 to 100java program to print prime numbers between 1 and 100write a java program to check number is prime or notprint prime numbers from 1 to 100 using java with explanationprime number 1 to 50 in javatotal prime in java in given rangeto print all the prime number in javaprogram to find prime number upto n in java with lrecursionhow to find prime numbers from 1 to 100 in java using switchprime numbers 1 to 100 in javaprogram to print prime number for given number of terms javaprime num java23 29 java program to find the prime numbers between 1 to 100 how to make function prime javaprime number javawrite a program to print all prime numbers up to n javaprime number program in javajava program to print 100 prime numbersgenerate list of prime numbers javaprint all the prime number between range javajava prime numbersprime numbe check javaprimes in javaa prime number is a whole number greater than 1 that is divisible by 1 and itself only write a program that determines the first 50 prime numbers in javajava program to count prime numbers between 1 and 10000list of prime numbers 1 100 program logicjava program to chekc whether number is primelogic to find prime numbers from specific range javaprime number java rerange of prime numbers in javacode to print prime number in javajava program to loop for first 100000 positive prime numbersprime or not 0 to 100 javaprint prime number in given range in javaprime numbers in a given range in javahow to generate prime numbers in javaprint prime numbers with exponents using javaprogram to print the prime number in the range in javajava program to print prime numbers or same numberprime number counter c2 a8 javaprime nmber in javaprint all prime numbers from 100 to 1 in javatotal number of prime numbers between 1 to 100 javaget prime number in javaprint all prime numbers in a given range in javajava program print prime numbers upto nprint list of prime numbers in javaprint prime numbers in between 1 to user entered javajava prime number program38 finding prime numbers in a given range javafind all prime numbers javacheck prime number in a given range javajava program to find number of prime numbers in a rangehow to find the prime numbers in java methodhow to print prime numbers and sum of the numbers in javajava program to check whether number is prime or nothow to get a list of prime nu 2cbers javalist of prime numbers program in javaprime number from 1 to 100 javasimple prime number finder javaprime no javajava program to print range of prime numbers upto given numberprime number java rangeprime number in range in javais prime number java best wayjava find a prime numberjava program to display prime numbers from 2 to 100return all prime numbers from 1 to 100class to print a set of prime numbers in javaprime number in java using 2fcondition for prime number in javaprogram to find prime numbers java between a to bjava program to find prime numbers in an arraymaking list of prime numbers javahow to find a prime number in javaprime number in java from 1 to 100prim function javaprint the prime number from 1 to n in java20 write a java program to print prime number from 2 to n to print all prime numbers between 1 to 100 in javaprint n prime numbers in javawriting a java function to count the prime numbers in given rangeall prime numbers between 1 to 100 in java while loophow to find prime no upto n number in javaprint all prime numbers from 2 to n javato write a java program to read a number from user and check whether it is prime of not prime number function javafind prime numbers in a range in javaprime number code javawrite a program to display prime number between 1 to 100 write logic to print prime numbers between 1 to 100 2ajava program to print prime numbers from 2 to nallintitle 3ajava program to print prime numbers upto nprime numbers between 1 to 50 using thread code with expaination in javafunction to check prime number in javahow to check the no is prime or not in javajava list of primesprime i javahow to find prime numbers in java1 to 1000 prime numbers program in javajava code to display count of prime numbers in a rangeprime no in javaprime number from 1 to n in javatake n as input print all prime numbers from 2 to n javawrite a java program to print all prime numbers in the interval 5ba 2cb 5d 28a and b 2c both inclusive 29 prime number generator in javajava print all prime numbersprime numbers between 1 to 10 in javajava prime nuberjava program to print prime numbers from m to n using for loopjava code to generate prime number1 to 100 prime numbers javahow to print prime numbers and sum of the prime numbers in javajava code for prime number from 1 to 100prim number list javafinding prime numbers in a given range javahow many prime numbers between 1 and 100 in javaeasy way to find n prime numbers in jvaprime numbers between 1 to 100 javafunction in java to check prime numberhow to find primes javaprime numbers upto a given number in javaprint prime numbers from 1 to 100 in java with explanationprint all prime numbers between two given numbers in javajava program to find sum of prime numbers between 1 and 100java program to print prime numbers in a given rangejava code to determine prime numbers in a rangewrite a program to print all prime numbers from 1 to 100 in javaprime numbers in a range javaprint prime numbers from 1 to n in javajava find prime numbers 1 100write a program in java to print all prime numbers between n and m print prime numbers from given number in javaprogram to print range of prime numbers in javaprint prime numbers between two numbers javaprint prime number javaprime numbers in 100 javajava program to print prime numbers between 10 and 99prime number and 1 program in javaprimenumbers javajava print prime numbersprime number betwwen 1 to hundred javaprime number between 1 to 100 in javaprime no from given range program in javaprime numerbs javaprime numbers from 1 to 100 javajava program get 50 prime numbersprime number in java in rangewap to print first n prime numbers in javajava prime numbers from 1 to 100print prime number in range javaprime numbers program in java between 1 to 100 sumhow to find prime numbers in a given range in javajava print all prime numbers that can be made form a numberjava program for prime numbers till njava prime number with array exampleprime number java programjava program to print prime numbersjava prime number methodjava program to print prime numbers in a given range