Re: find 100 first prime number

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 1
Reputation: jips11in is an unknown quantity at this point 
Solved Threads: 0
jips11in jips11in is offline Offline
Newbie Poster

Re: find 100 first prime number

 
0
  #1
Oct 11th, 2007
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);
}
}
}

}
}
Last edited by jips11in; Oct 11th, 2007 at 3:57 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: find 100 first prime number

 
0
  #2
Oct 11th, 2007
And ?
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: find 100 first prime number

 
0
  #3
Oct 11th, 2007
actually, it prints the first 102 prime numbers (if it works at all)...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 1
Reputation: -ordi- is an unknown quantity at this point 
Solved Threads: 0
-ordi- -ordi- is offline Offline
Newbie Poster
 
0
  #4
4 Days Ago
  1. public class Algarv {
  2. public static void main(String args[]) {
  3. int numbrid = 0; // Proovime kohe algusest
  4. int loendur = 0; // Loendame üles, et pärast lihtsam oleks
  5. while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100
  6. {
  7. numbrid++;
  8. if(numbrid % 2 != 0)
  9. {
  10. int abi = 3;
  11. while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2)))
  12. {
  13. abi++;
  14. }
  15. if(numbrid % abi != 0)
  16. {
  17. loendur++;
  18. System.out.print(numbrid+" ");
  19. System.out.println(loendur);
  20. }
  21. }
  22. }
  23. }
  24. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 23
Reputation: tjsail is an unknown quantity at this point 
Solved Threads: 1
tjsail tjsail is offline Offline
Newbie Poster
 
0
  #5
3 Days Ago
1 is not technically a prime number either so it is not true to print it out as prime with two and three.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,678
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #6
3 Days Ago
Originally Posted by -ordi- View Post
  1. public class Algarv {
  2. public static void main(String args[]) {
  3. int numbrid = 0; // Proovime kohe algusest
  4. int loendur = 0; // Loendame üles, et pärast lihtsam oleks
  5. while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100
  6. {
  7. numbrid++;
  8. if(numbrid % 2 != 0)
  9. {
  10. int abi = 3;
  11. while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2)))
  12. {
  13. abi++;
  14. }
  15. if(numbrid % abi != 0)
  16. {
  17. loendur++;
  18. System.out.print(numbrid+" ");
  19. System.out.println(loendur);
  20. }
  21. }
  22. }
  23. }
  24. }
For future reference, please have your comments in the code in English
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC