import java.util.
ArrayList;
import java.util.List;
import java.util.Scanner;
public class PinValidator {
private static boolean isPrime(int number) {
if (number < 2)
return false;
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0)
return false;
}
return true;
}
private static boolean isComposite(int number) {
if (number < 4)
return false;
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0)
return true;
}
return false;
}
private static boolean isValidPin(int pin) {
int firstDigit = pin / 1000;
int secondDigit = (pin / 100) % 10;
int thirdDigit = (pin / 10) % 10;
int fourthDigit = pin % 10;
return firstDigit % 2 != 0 && secondDigit % 2 == 0 && isPrime(thirdDigit)
&& isComposite(fourthDigit);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the total number of PIN numbers:");
int totalPins = scanner.nextInt();
if (totalPins <= 0) {
System.out.println(totalPins + " is an invalid number");
scanner.close();
return;
}
System.out.println("Enter the PIN numbers:");
List<Integer> validPins = new ArrayList<>();
for (int i = 0; i < totalPins; i++) {
int pin = scanner.nextInt();
if (pin < 1000 || pin > 9999) {
System.out.println(pin + " is an invalid PIN number");
} else if (isValidPin(pin)) {
validPins.add(pin);
}
}
scanner.close();
if (validPins.isEmpty()) {
System.out.println("All these " + totalPins + " numbers are not a valid
PIN number");
} else {
System.out.println("Valid PIN numbers are:");
for (int pin : validPins) {
System.out.println(pin);
}
}
}
}