galinyotsev123

ProgBasicsJavaBook7.1ComplexLoop10checkPrime

Jan 14th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E10checkPrime {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. boolean prime = n >= 2;
  9.  
  10. for (int i = 2; i <= Math.sqrt(n); i++) {
  11. if (n % i == 0) {
  12. prime = false;
  13. break;
  14. }
  15. }
  16. if (prime) {
  17. System.out.println("Prime");
  18. } else {
  19. System.out.println("Not Prime");
  20. }
  21.  
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment