java program to print prime numbers upto n

Solutions on MaxInterview for java program to print prime numbers upto n by the best coders in the world

showing results for - "java program to print prime numbers upto n"
Alessandra
17 Aug 2018
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}
Kaylen
07 Sep 2018
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}
Clelia
07 Jan 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}
Isabella
10 Nov 2016
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}
Natalia
19 Feb 2017
1public class PrimeNumbersFrom1To100
2{
3   public static void main(String[] args)
4   {
5      int maxNumber = 100;
6      boolean prime = true;
7      String primeNumbers = "";
8      for(int a = 1; a <= maxNumber; a++)
9      {
10         prime = checkPrime(a);
11         if(prime)
12         {
13            primeNumbers = primeNumbers + a + " ";
14         }
15      }
16      System.out.println("Display prime numbers from 1 to " + maxNumber + ": ");
17      System.out.println(primeNumbers);
18   }
19   public static boolean checkPrime(int number)
20   {
21      int remainder;
22      for(int a = 2; a <= number / 2; a++)
23      {
24         remainder = number % a;
25         // if remainder is equal to 0 then number is not prime
26         if(remainder == 0)
27         {
28            return false;
29         }
30      }
31      return true;
32   }
33}
queries leading to this page
write a java program to find prime no between 1 to 1000java 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 javaprint 1 100 prime numbers in javaprint prime numbers javahow to make print a prime numbers in javato print all the prime numbers between 1 to 100 in javaprime number printing within a given range in javajava program to find prime number between 1 and 100print 11 prime number per lineprint n number of prime numbers in javawrite a program 2c which prints all the prime numbers in the range of two given numbers m and n in javaprime numbers between 1 to 100 codeall the prime numbers till n 21 in 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 javaprinting prime numbers in javawrite a program to find prime number in a given range in javajava program to print prime numbers 1 to 100prime numbers from 1 to 100 java programjava print n prime numberscreate a program that displays prime numbers from 1 to 100print the distance between the first 100 prime numberswrite java code to find prime number between 1 to 100prime numbers between 2 to 100 in javaprint prime numbers from 1 to 100 or notjava for loopprime number program java print 1 100generate 100000 prime number in javaprime number till 10 5e12 javatotal 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 javaprime 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 javadisplay prime numbers from 1 to 100 in javajava program to print first 50 prime numbersprime 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 javarange of prime number program in javahow many prime numbers are there from 1 100 in javaprime numbers 1 100 javaprime number from 1 to 50 in javaprime number program 1 100 in javaprime number in rangein javaprint first 10 prime number from 1 to 100 in javaprint 1 to n prime numbers in javaprime number program in java between 1 to 100java program to print all prime numbers in an interval1 to 100 prime numbers java programcheck prime numbers 1 100 javaprime number in a range in javaprime number in java 1 to 100java program to print prime numbers upto njava program to print prime number seriesinput prime numbers function in javawap to print the first 10 prime numbers from 1 to 100 in javajava program to count prime numbers between 1 and 100prime numbers from 1 to 100 in javaprint prime numbers in java 1 to 100print first n prime numbers in javajava to print all prime numbers smaller than nprime numbers 1 to 50 program in javaprint prime numbers in javaget prime number till 10 5e5 jav aprime numbers upto given number in javaprint prime numbers from 1 to 100 in java by checking consecutive numberscode to print all prime numbers up to 100 javacreate a program that displays 5 digit prime numbers in javaprime numbers till 100 codingformula to find prime numbers between 1 and 100 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 javato print the prime numbers in javafind prime numbers between 0 to 100 javaprime number 1 to 50 program in java to print all prime numbers between 1 to 100 in javajava list of prime numbersprime numbers between 1 and 100 in javaprint prime numbers from 1 to 100 in java print hello for every set of 10print 1 to 100 prime number in javajava program to print 1 to 100 prime numbersjava prime number allallintitlle 3ajava program to print prime numbers from 2 to na program in java to print prime numbers from 1 to n 28user input 29prime numbers java 1 to 100prime numbers upto n in javaprogram to display prime numbers from 1 to 100write a program to print prime numbers between 10 and 99 prime no between 1 to 100 in javaprint 100 prime numbers in javaprint prime number using javaprime numbers from 1 to 100 in java best caseprint 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 rangebest way to print prime numbers in javajava code to find prime numbers between m and nhow to prime numbers first 100 prime number javaget all prime numbers from 1 10000 in javadisplay all prime number and non prime number in javaprint prime numbers between two numbers in javaprime numbers finding in given number range using javato print the prime numbers in javawrite a program to print prime numbers from 1 to 100 in javafind the prime numbers from 1 to 100 in javajava program to print all prime numbers between 1 to 100how to print prime numbers in javaprint range of prime numbers in javahow to find prime numbers between start and end javaprime numbers from 1 to 50 javaprint prime numbers using javaget the prime number in range in javahow to find prime numbers in a range javaprime number program in java up to 100prime number program in java print from 1 to 50 prime number between 1 to 100 program in javajava program to print all prime numbers till njava program to display all prime numbers from 1 to nprime 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 javaprogram to calculates all prime numbers in given range and store them in an array in javafind prime number in range javaprime number program in java print 1 to 100generate prime numbers in javaprime number program from 1 to 50 in javahow to calculate all the prime numbers in a for loop in javawap to print all prime numbers between 1 to 100 in javaprint prime numbers from 1 to 100 in javajava program to display prime numbers between 1 to nprint all prime numbers from x to 1 in javaprime numbers till n 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 numberprime numbers from 1 to 100 java program 2c separatedhow to find prime numbers from 1 to 100 in javaprint all prime numbers from 1 to n 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 javawrite a program to print prime numbers in javaprint prime numbers upto n in java java program for picking prime numbers in a given rangejava 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 loopprime number 1 to 1000 using java programhow to find number of prime numbers up to to n javaprint prime number in 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 waylist of prime numbers from 1 to 100 in javaprint prime numbers list javajava calculate prime number 1 1000000 5dcheck prime numbers in java between 1 and 100prime number from 0 to 100 javaprime no 1 to 100 javaprime numbers between 1 to 100 in javajava program to display prime numbers from 1 to 100java program to print prime numbers between 1 and 100print 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 java23 29 java program to find the prime numbers between 1 to 100 write a program to print all prime numbers up to n javajava program to print 100 prime numbers1 100 prime numbers in javaprint all the prime number between range 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 logiclogic to find prime numbers from specific range javaprime numbers 1 to 100 javarange of prime numbers 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 javaprint prime numbers with exponents using javaprogram to print the prime number in the range in javajava program to print prime numbers or same numberprint all prime numbers from 100 to 1 in javatotal number of prime numbers between 1 to 100 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 java38 finding prime numbers in a given range javafind all prime numbers javaeasy way to print prime numbers in javacheck prime number in a given range javajava program to find number of prime numbers in a rangehow to print prime numbers and sum of the numbers in javajava program to display prime numbers from 1 to nprime number from 1 to 100 javajava program to print range of prime numbers upto given numberprime number java rangeprime numbers up to 100 javaprime number in range in javajava program to display prime numbers from 2 to 100return all prime numbers from 1 to 100print 1 to 100 prime numbers in javaprogram to find prime numbers java between a to bprime number in java from 1 to 100print 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 javafind prime numbers in a range in 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 nprint prime numbers from 1 to 100 in continuous form javaprime numbers between 1 to 50 using thread code with expaination in javaall prime numbers between 1 to 100 in java1 to 1000 prime numbers program in javajava code to display count of prime numbers in a rangeprime numbers program in java 1 to 100 all sumprime 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 java print all prime numbersprime numbers between 1 to 10 in javajava 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 100finding prime numbers in a given range javahow many prime numbers between 1 and 100 in javanumber of prime numbers till n javafind prime number between 1 to 100 best javawrite a java program to find the prime numbers from 1 to 100prime numbers between 1 to 100 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 100find prime number between 1 to 100 in javawrite 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 javaprime numbers between 1 to 50 using thread 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 javajava print prime numbersprime number betwwen 1 to hundred javaprime number between 1 to 100 in javaprime no from given range program in javaprint prime numbersprime 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 javaall prime numbers program in javaprime number from 1 to 100 java codeprime 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 prime numbers from 1 to 100 gfgjava program for prime numbers till njava program to print prime numbersjava program to print prime numbers upto n