65. JAVA Program to find all the Prime numbers from 1 to 99.
How does this program work?
- This program is used to find all the Prime numbers from 1 to 99 using JAVA.
- Prime number means which is only divisible by 1 and that number itself, and cannot divisible by any other number.
- First store the number into variable, then we will find the remainder using loop.
- The counter will be increment if remainder zero, Once number can be divisible by some other number instead of 1 and that number itself, If its value less than three means its a primer number.
Here is the code
//Print Prime Numbers from 1 to 99.
public class prime{
public static void main(String[] args)
{
int i, number, count;
System.out.println(" Prime Numbers from 1 to 100 are : ");
for ( number = 1; number <= 100; number++ )
{
count = 0;
for ( i = 2; i <= number/2; i++ )
{
if ( number % i == 0 )
{
count++;
break;
}
}
if ( count == 0 && number != 1 )
{
System.out.print(number + " ");
}
}
}
}