Answer :

Answer:

MARK AS BRAINLIST PLZ

Explanation:

Sure! Below is a Java program that prints the first 7 prime Fibonacci numbers.

```java

import java.util.ArrayList;

import java.util.List;

public class PrimeFibonacci {

public static void main(String[] args) {

List<Integer> primeFibonacciNumbers = new ArrayList<>();

int count = 0;

int a = 0, b = 1;

while (primeFibonacciNumbers.size() < 7) {

int fibonacci = a + b;

a = b;

b = fibonacci;

if (isPrime(fibonacci)) {

primeFibonacciNumbers.add(fibonacci);

}

}

System.out.println("First 7 prime Fibonacci numbers: " + primeFibonacciNumbers);

}

public static boolean isPrime(int number) {

if (number <= 1) {

return false;

}

for (int i = 2; i <= Math.sqrt(number); i++) {

if (number % i == 0) {

return false;

}

}

return true;

}

}

```

### Explanation:

1. **PrimeFibonacci Class**: The main class where the program execution begins.

2. **Main Method**: This method generates Fibonacci numbers and checks if they are prime.

- It initializes an `ArrayList` to store the first 7 prime Fibonacci numbers.

- It uses two variables `a` and `b` to generate Fibonacci numbers.

- In each iteration, it calculates the next Fibonacci number and checks if it is prime using the `isPrime` method.

- If a Fibonacci number is prime, it adds it to the list.

- The loop continues until we have collected 7 prime Fibonacci numbers.

3. **isPrime Method**: This method checks if a given number is prime.

- It returns `false` if the number is less than or equal to 1.

- It checks divisibility from 2 up to the square root of the number.

- If any divisor is found, it returns `false`; otherwise, it returns `true`.

### Running the Program:

- Compile the program using `javac PrimeFibonacci.java`.

- Run the compiled program using `java PrimeFibonacci`.

- The output will display the first 7 prime Fibonacci numbers.

I HOPE THIS IS HELPFUL FOR YOU

Other Questions