Advertisement
riking

PrimeFinder

Mar 6th, 2011
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.io.PrintStream;
  2.  
  3. public class PrimeFinder {
  4.     int start;
  5.     int stop;
  6.     int cnum;
  7.    
  8.     public void main (String args[]) {
  9.         start = 2450;
  10.         stop = 2504;
  11.         if (stop>=start) { throw new IllegalArgumentException("Interval is 0 or less"); }
  12.         for (cnum=start; cnum!=stop; cnum++) {
  13.             if (checkprime(cnum)) {
  14.                 System.out.println(cnum);
  15.             }
  16.         }
  17.     }
  18.    
  19.     private boolean checkprime(int num) {
  20.         int i;
  21.         for (i=2; i <= (Math.sqrt(num)+1); i++) {
  22.             if ((num % i)!=0) {
  23.                 return false;
  24.             }
  25.         }
  26.         return true;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement