Question 1 :
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.Accept two positive integers m and n, where m is less than n as user input.Display all Prime-Adam integers that are in the range between m and n (both inclusive) and output them along with the frequency, in the format given below:
Test your program with the following data and some
random data:
Example 1
INPUT: m=5
n=100
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS:3
Example 2
INPUT: m=100 n=
200
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS:3
Example 3
INPUT:m= 50 n =
70
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:NIL
FREQUENCY OF PRIME-ADAM INTEGERS IS:0
Example 4
INPUT: m=700 n
=450
OUTPUT: INVALID INPUT.
import java.util.*;
public class
ISC2020Q1 {
public
static void main(String[] args) {
int m,n;
Scanner in = new
Scanner(System.in);
do {
System.out.println("INPUT: Enter the value of m and n:");
m = in.nextInt();
n= in.nextInt();
if(m <=0 || n <= 0 || m > n )
System.out.println("Wrong input, please try again:");
}while
( m <=0 || n <= 0 || m > n);
PrimeAdam obj = new PrimeAdam(m,n);
obj.displayPrimeAdam();
in.close();
}
}
class PrimeAdam {
public
void displayPrimeAdam() {
System.out.print("THE PRIME ADAM INTEGERS ARE:");
for (int i=m; i<=n; i++) {
if(isPrime(i)==true)
if (i*i ==
reverseNumber(reverseNumber(i)*reverseNumber(i))) {
System.out.print(i+" ");
frequency++;
}
}
System.out.println();
if (frequency
==0)
System.out.println("NIL");
System.out.println("FREQUENCY OF PRIME-ADAM INTEGER(S) IS:"+frequency);
}
private
int reverseNumber(int numb) {
int temp=0;
int rem,i;
String s;
s=Integer.toString(numb);
i=s.length()-1;
do {
rem = numb%10;
temp += rem*(int)Math.pow(10,
i);
i--;
numb /= 10;
}while(
numb > 0);
return
temp;
}
private
boolean isPrime(int numb) {
PrimeFlag
= true;
for( int i = 2; i <= (int)Math.sqrt(numb); i++) {
if (numb%i == 0) {
PrimeFlag
= false;
break;
}
}
return
PrimeFlag;
}
PrimeAdam (int m, int n) {
this.m = m;
this.n = n;
frequency
= 0;
}
private
int m;
private
int n;
private
int frequency;
private
boolean PrimeFlag;
}
Thankyou sir/ Ma'am 🙏🏻
ReplyDeleteHelping Students! Feel free to send your problems. Follow us on the most popular platforms for help in mathematics
Deletehttps://facebook.com/prime.maths
https://instagram.com/prime.maths
https://YouTube.com/c/PrimeMaths
https://twitter.com/prime_maths
https://t.me/PrimeMaths
As we all know, after the 10th level CBSE board examinations, the subject layout becomes precise, and students are given a choice to opt for a stream that best suits them. Mohali Board 12th Model Paper 2021
ReplyDeleteThe Demand for Silver always rises every day in China and India, as the raising Gold rate has shifted the Investor’s interest in Silver metal, and thus having a good demand in industries along with the most valuable jewelry and silverware, silver today rate Silver is one such that comes under commodities including Gold, platinum, and other valuable precious items, thus Market always offers an individual to invest in Commodity Market rather than moving to equity or mutual funds which don’t stand still every time.
ReplyDeletesir algorithm kyu nhi dala
ReplyDeleteKaafi samay lagta hai.
Delete