SeanNers

PrimeNum

Aug 18th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class PrimeNum {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6. int a = input.nextInt();
  7. int b = input.nextInt();
  8.  
  9. for(int i = a ; i <= b ; i++ ) {
  10. if ( i == 2 || i == 3 ) System.out.println(i);
  11. int root = (int) Math.sqrt(i);
  12.  
  13. for(int j = 2; j <= root ; j++ ) {
  14. if ( (i % j) == 0 ) break;
  15. if ( j == root ) System.out.println(i);
  16. }
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment