Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BiggestPrimeNumber {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- Boolean[] isPrime = new Boolean[n];
- for (int i = 0; i < isPrime.length; i++) {
- isPrime[i] = false;
- }
- for (int i = 2; i <= n ; i++) {
- int count = 0;
- for (int j = 1; j <= i ; j++) {
- if (i % j == 0) {
- count++;
- }
- }
- if (count == 2) {
- isPrime[i - 2] = true;
- }
- }
- for (int i = isPrime.length - 1; i > 0 ; i--) {
- if (!isPrime[i]) {
- continue;
- }
- System.out.println(i + 2);
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment