Advertisement
coderrohan14

LoopingQues4.java

Jun 27th, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Solution {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int a = sc.nextInt(),b=sc.nextInt();
  7. for(int i = a;i<=b;i++){
  8. if(isPrime(i)){
  9. System.out.print(i+" ");
  10. }
  11. }
  12. }
  13. static boolean isPrime(int n) {
  14. if (n == 2 || n == 3)
  15. return true;
  16. if (n % 2 == 0)
  17. return false;
  18. for (long i = 3; i * i <= n; i += 2) {
  19. if (n % i == 0)
  20. return false;
  21. }
  22. return n != 1;
  23. }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement