-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadam_number.java
More file actions
40 lines (33 loc) · 1.12 KB
/
adam_number.java
File metadata and controls
40 lines (33 loc) · 1.12 KB
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
import java.util.*;
class adam{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter A Number :");
int num=scan.nextInt(); //taking input from user
int rev=reverse(num);//calling the function to reverse the number
if(reverse(num*num)==rev*rev)//comparing the square of the reverse of the number with the square of the number 169==169
{
System.out.println("Its a Adam Number");
}
else //if not equal
{
System.out.println("Its Not a Adam Number");
}
}
static int reverse(int num)
{
int rev=0;
while(num!=0)
{
rev=rev*10+num%10;
num/=10;
}
return rev;
}//function to reverse the number
}
//Complexity Analysis:
//Time Complexity: O(log N)
/*Reason: The time complexity of the code is O(log N) because the code
has a while loop that runs log N times,where N is the input number.
The code inside the while loop has a constant time complexity,
so the overall time complexity of the code is O(log N).*/