WAP to input 25 numbers in an array and
replace all the prime digits in a no. to its
next print prime digit no
Eg - 456 become 476, 879 become 8119
Answers
Answer:
good night jaan sweet dreams ka matalab yah to do go ci joint secretary and u will be able I have to be v and u
DETAILED EXPLANATION:-
import java.util.Scanner;
class Program {
static int getNextPrime(int num) {
int x = num + 1;
while (true) {
if (isPrime(x)) {
break;
} else {
x += 1;
}
}
return x;
}
static boolean isPrime(int num) {
int numberOfFactors = 0;
for (int i = 1 ; i <= num ; i++) {
if (num % i == 0) {
numberOfFactors += 1;
}
}
if (numberOfFactors > 2) {
return false;
} else {
return true;
}
}
public static void main(String[] args) {
int array[] = new int[5];
Scanner sc = new Scanner(System.in);
for (int i = 0 ; i < array.length ; i++) {
System.out.print("Enter a number: ");
array[i] = sc.nextInt();
}
System.out.println("[*]\tDetecting prime numbers");
for (int i = 0 ; i < array.length ; i++) {
if (isPrime(array[i])) {
System.out.println("[+]\t" + array[i] + " is a prime number. The next prime number is : " + getNextPrime(array[i]));
}
else {
System.out.println("[X]\t" + array[i] + " is not a prime number.");
}
}
}
}