Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board What is the 10001st prime number? Download Source Code
Author Details Code Information
perito

Pinned 7 Codes
Posted 0 Coding Articles

Send A Message
View Coders Profile
Language Java
Expires Never
Length 603 Characters (30 Lines)
Password no password
  1. //What is the 10001st prime number?
  2. public class Problem7
  3. {
  4.           public static boolean isPrime(int nbr)
  5.           {
  6.                     if (nbr == 1) return false;
  7.                     boolean isNPrime=true;
  8.                     for (int i = 2; i < nbr; i++)
  9.                               if ((nbr != i) && (nbr % i == 0))
  10.                               {
  11.                                         isNPrime = false;
  12.                                         break;
  13.                               }
  14.                     if (isNPrime == true) return true;
  15.                     else return false;
  16.           }
  17.           public static void main(String[] args)
  18.           {
  19.                     int counter = 0;
  20.                     int i = 2;
  21.                     while(counter < 10001)
  22.                     {
  23.                               if (isPrime(i))
  24.                                         counter++;
  25.                               i++;
  26.                     }
  27.                     i--; // i++ will itirate one extra time, so we subtract one
  28.                     System.out.println(i);
  29.           }
  30. }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved