Note: A Prime number is a natural number which is greater than 1 and that has no posotive divisor
other than 1 & itself.
Ex :- 2,3,5,7,11,13,17,19,23......
*/
import static java.lang.System.out;
import java.util.Scanner;
class Prime2
{
static public void main(String...alt)
{
int count=0;
for(int j=2;j<=100;j++)
{
int flag=0;
for(int i=2;i<=j/2;i++)
{
if(j%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
out.println(j);
}
}
out.println("Total Prime No b/w 1 to 100 = "+count);
}
}
other than 1 & itself.
Ex :- 2,3,5,7,11,13,17,19,23......
*/
import static java.lang.System.out;
import java.util.Scanner;
class Prime2
{
static public void main(String...alt)
{
int count=0;
for(int j=2;j<=100;j++)
{
int flag=0;
for(int i=2;i<=j/2;i++)
{
if(j%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
out.println(j);
}
}
out.println("Total Prime No b/w 1 to 100 = "+count);
}
}
0 Comment to "Java Program to print & count all prime number between 1 to 100."
Post a Comment