class Prime
{
int n;
Prime(int nn)
{
n=nn;
}
void calc()
{
int i,j;
System.out.println("Prime Nos. from 1 to "+n +" : ");
for(i=2;i<=n;i++)
{
for(j=2;j<=i;j++)
{
if(i==j)
{
System.out.print(i +"\t");
break;
}
if(i%j==0)
{
break;
}
}
}
}
};
class Exp2_2
{
public static void main(String[] args)
{
Prime p = new Prime(20);
p.calc();
}
}
No comments:
Post a Comment