## Prime Number Program in Java

A prime number is a characteristic number more than 1 that has no positive divisors other than 1 and itself. For instance 2, 3, 5, 7… are prime numbers. Let’s see the prime number program in java, Program to check the prime numbers from 1 to 100 :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | class PrimeNumbers1To100 { public static void main (String[] args) { int i =0; int number =0; //Empty String String pNumbers= ""; for (i = 1; i <= 100; i++) { int count=0; for(number =i; number>=1; number--) { if(i%number==0) { count = count + 1; } } if (counter ==2) { pNumbers= pNumbers + i + " "; } } System.out.println("Prime numbers from 1 to 100 are :"); System.out.println(primeNumbers); } }0 |

Output : Read Also: Fibonacci Series in Java Prime Number … Read morePrime Number Program in Java