Write a program to input an integer and check whether all are prime digits or not
Answers
Answer:
we will take a number variable and check whether the number is prime or not.
public class PrimeExample{
public static void main(String args[]){
int i,m=0,flag=0;
int n=3;//it is the number to be checked.
m=n/2;
if(n==0||n==1){
System.out.println(n+" is not prime number");
}else{
Answer:
Here is a Python program that takes an integer as input and checks whether all of its digits are prime or not:
num = int(input("Enter an integer: "))
is_all_prime = True
# Check each digit in the number
while num > 0:
digit = num % 10
if digit not in [2, 3, 5, 7]:
is_all_prime = False
break
num //= 10
# Output the result
if is_all_prime:
print("All digits are prime")
else:
print("Not all digits are prime")
In this program, we first take an integer as input from the user. We then use a while loop to extract each digit from the number, starting with the ones digit. For each digit, we check if it is one of the prime digits 2, 3, 5, or 7. If a digit is not prime, we set the `is_all_prime` variable to False and break out of the loop. Finally, we output the result based on the value of `is_all_prime`.