| | |
Re: find 100 first prime number
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Solved Threads: 0
THis is program in java for First 100 Prime Number as "count<100" .
public class PrimeNumber
{
public static void main(String args[])
{
int num=4;
int count=0;
System.out.println("First 100 Prime Number is: ");
System.out.println("1");
System.out.println("2");
System.out.println("3");
while(count<100)
{
num++;
if(num%2!=0)
{
int dv=3;
while((num%dv!=0)&&(dv<=((num-1)/2)))
{
dv++;
}
if(num%dv!=0)
{
count++;
System.out.println(num);
}
}
}
}
}
public class PrimeNumber
{
public static void main(String args[])
{
int num=4;
int count=0;
System.out.println("First 100 Prime Number is: ");
System.out.println("1");
System.out.println("2");
System.out.println("3");
while(count<100)
{
num++;
if(num%2!=0)
{
int dv=3;
while((num%dv!=0)&&(dv<=((num-1)/2)))
{
dv++;
}
if(num%dv!=0)
{
count++;
System.out.println(num);
}
}
}
}
}
Last edited by jips11in; Oct 11th, 2007 at 3:57 am.
•
•
Join Date: Dec 2009
Posts: 1
Reputation:
Solved Threads: 0
0
#4 4 Days Ago
Java Syntax (Toggle Plain Text)
public class Algarv { public static void main(String args[]) { int numbrid = 0; // Proovime kohe algusest int loendur = 0; // Loendame üles, et pärast lihtsam oleks while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100 { numbrid++; if(numbrid % 2 != 0) { int abi = 3; while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2))) { abi++; } if(numbrid % abi != 0) { loendur++; System.out.print(numbrid+" "); System.out.println(loendur); } } } } }
0
#6 3 Days Ago
•
•
•
•
Java Syntax (Toggle Plain Text)
public class Algarv { public static void main(String args[]) { int numbrid = 0; // Proovime kohe algusest int loendur = 0; // Loendame üles, et pärast lihtsam oleks while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100 { numbrid++; if(numbrid % 2 != 0) { int abi = 3; while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2))) { abi++; } if(numbrid % abi != 0) { loendur++; System.out.print(numbrid+" "); System.out.println(loendur); } } } } }
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: edit windows registry using java...
- Next Thread: help with GUI, Exception
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array arrays automation binary blackberry block bluetooth character chat class classes client code compile component consumer database desktop developmenthelp eclipse error event exception fractal freeze ftp game givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaee javaprojects jmf jni jpanel julia lego linked linux list loop loops mac map method methods mobile netbeans newbie number online oracle page print printf problem program programming project properties recursion researchinmotion rotatetext rsa scanner screen server set singleton size sms sort sql string swing template textfields threads time title tree tutorial-sample update windows working






