Advertisement
wadkat

Java prime range

Nov 15th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package q1;
  6. import java.util.Scanner;
  7. public class q7 {
  8. public static void main(String[]args){
  9. int count=1, a1,a2,flag;
  10. Scanner keyboard = new Scanner(System.in);
  11. System.out.println("Enter first number:");
  12. a1=keyboard.nextInt();
  13. System.out.println("Enter first number:");
  14. a2=keyboard.nextInt();
  15.  
  16. while(a1<=a2)
  17. {flag=1;
  18.  
  19. for(count=2; count<a1;count++)
  20. {
  21. if (a1%count==0)
  22. {
  23. flag=0;
  24. break;
  25. }
  26. }
  27. if(flag==1)
  28. System.out.println(a1+" ");
  29. a1++;
  30.  
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement