This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
see for your self
Posted by megha gupta on February 17, 2002 at 11:46 PM
> hi, > pl. find below the program to display the first 100 prime nos. > ................................................................. > > //program that prints first 100 prime no.s > import java.util.*; > public class prime2 > { > public static void main(String[] args) > { int index=2,x=3; > ArrayList al=new ArrayList(); > while(index<100) > { > //int x=Integer.parseInt(args[0]); > if(x%2==0) > { System.out.println("hello The no. is not prime"); > } > else > { > double y=Math.sqrt(x); > //System.out.println(y); > double z=Math.ceil(y); > //System.out.println(z); > boolean state=true; > for (int i=3;i> { if(i%2==0 ) > continue; > if(x%i==0) > { > //System.out.println("The no. is not prime"); > //System.out.println("The no. is "+x); > //System.out.println(" It is divisible by "+i); > state=false; > //break; > } > } > if(state) > { > System.out.println("The no. is prime"); > > al.add(new Integer(x)); > index=index+1; > > > } > x=x+2; > } > } > > Object myobj[]=al.toArray(); > for(int i=0;i> System.out.println(myobj[i]+"\t"+i+""); > > > } > } > .................................................................> hope this helps > regards > swapnil
Replies:
|