Guest User

Untitled

a guest
Nov 9th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BiggestPrimeNumber {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8.  
  9. Boolean[] isPrime = new Boolean[n];
  10. for (int i = 0; i < isPrime.length; i++) {
  11. isPrime[i] = false;
  12. }
  13.  
  14. for (int i = 2; i <= n ; i++) {
  15. int count = 0;
  16. for (int j = 1; j <= i ; j++) {
  17. if (i % j == 0) {
  18. count++;
  19. }
  20. }
  21. if (count == 2) {
  22. isPrime[i - 2] = true;
  23. }
  24. }
  25.  
  26. for (int i = isPrime.length - 1; i > 0 ; i--) {
  27. if (!isPrime[i]) {
  28. continue;
  29. }
  30. System.out.println(i + 2);
  31. return;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment