import static java.lang.Math.*;
public class prictise_2
{
public static void main(String[] args)
{
for(int i=3;i<=50;i++)
{ int x=round((float)sqrt(i));
if(i%x!=0)
System.out.println(i);
}
}
}
这个求素数的程序,怎么不行呢
public class prictise_2
{
public static void main(String[] args)
{
for(int i=3;i<=50;i++)
{ int x=round((float)sqrt(i));
if(i%x!=0)
System.out.println(i);
}
}
}
这个求素数的程序,怎么不行呢
{
public static void getPrime(int n)
{
for(int i=1;i<=n;i++)
{
boolean prime=true;
double k=Math.sqrt(new Integer(i).doubleValue());
int m=new Double(k).intValue();
for(int j=2;j<=m;j++)
{
if(i%j==0)
{
prime=false;
}
}
if(prime)
{
System.out.print(i+" ");
}
}
}
public static void main(String[] args)
{
getPrime(100);
}}记得结贴哦!