AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



programming-basics: java program to find megaPrime number

megaprime if it is prime and all of its individual digits are prime

programming x 167
basics x 170
Posted On : 2017-09-30 16:31:15.0
profile Divesh - anyforum.in Divesh
102180
up-rate
3
down-rate

Answers


import java.util.Scanner;

public class MegaPrime {
public static void main(String[] args) {
System.out.println("Please Enter a number:");
Scanner input=new Scanner(System.in);
int number=input.nextInt();
System.out.println(isMegaPrime(number));
}

public static boolean isMegaPrime(int number){
if(isPrime(number)){
String num=String.valueOf(number);
for(int i=0;i<num.length();i++){
if(!isPrime(Integer.valueOf(Character.toString(num.charAt(i)))))
return false;
}
return true;
}else{
return false;
}
}

private static boolean isPrime(int num) {
if (num < 2) return false;
if (num == 2) return true;
if (num % 2 == 0) return false;
for (int i = 3; i * i <= num; i += 2)
if (num % i == 0) return false;
return true;
}
}

Posted On : 2017-10-01 14:51:10
Satisfied : 0 Yes  0 No
profile Saksham Kumar - anyforum.in Saksham Kumar
72933915851
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in