-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperfect_palindrome.java
49 lines (35 loc) · 1.04 KB
/
perfect_palindrome.java
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
import java.util.Scanner;
public class perfect_palindrome {
public static boolean palindrome(int a){
int b = a;
String palindrome = "";
do {
int c = b%10;
palindrome += c;
b = b/10;
} while (b>0);
int d = Integer.parseInt(palindrome);
boolean result = (a==d)?true:false;
return result;
}
public static boolean perfect(int z){
int sum = 0;
for (int i = 1; i<=(z/2); i++){
if(z%i==0){
sum += i;
}
}
boolean result = (z==sum)? true: false;
return result;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int a = sc.nextInt();
System.out.println("Is Palindrome? : "+ palindrome(a));
System.out.print("Enter a number: ");
int z = sc.nextInt();
System.out.println("Is Perfect? : "+ perfect(z));
sc.close();
}
}