JAVA Program To Check Given Number Is Prime-Adam or Not [ISC 2020 Practical]
Introduction:
A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as well as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself. Example: 2, 3, 5, 7.. etc.
Adam number: The square of a number and the square of its reverse are reverse to each other.
Example:
If n=13 and reverse of "n" =31, then,
(13)2 = 169
(31)2 =961 which is reverse of 169
thus 13, is an Adam number.Test your program with the following data .
-
EXAMPLE 1
INPUT:103
OUTPUT:YES IT IS!! -
EXAMPLE 2
INPUT:113
OUTPUT:YES IT IS!! -
EXAMPLE 3
INPUT:112
OUTPUT:NOPE!!
CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /** * QUESTION : A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as well as an Adam number. * @theschoolprogrammer * www.theschoolprogrammer.com */ import java.util.*; public class PrimeAd { static boolean Prime(int n)
//converting number to string for easy algorithm int i; String ns=""; for(i=0;i<s.length();i++) { ns=s.charAt(i)+ns; } return(Integer.valueOf(ns)); } static void main() { Scanner sc=new Scanner(System.in); System.out.println("ENTER FIRST NUMBER"); int n=sc.nextInt(); int k=(int)Math.pow(Reverse(n),2); if((Prime(n)==true) &&(Reverse(n*n)==k)) { System.out.print("YES IT IS!!"); } else System.out.print("NOPE"); } } |
Comments