forked from Gomavijayan/Java_Accenture_LearningModules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber Category.java
More file actions
81 lines (73 loc) · 1.56 KB
/
Number Category.java
File metadata and controls
81 lines (73 loc) · 1.56 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public interface NumberCategory{
public boolean checkNumberCategory(int num1,int num2);
}
//=========================================//
import java.util.*;
public class NumberCategoryUtility{
static int findFactor(int n){
int i;
int sum=0;
for ( i=1; (i*i)<n; i++){
if(n%i==0){
sum+=i;
}
}
if(i-(n/i)==1){
i--;
}
for (;i>1; i--){
if(n%i==0){
sum+=(n/i);
}
}
return sum;
}
public static boolean isPalindrome(int num){
String n=String.valueOf(num);
int i=0;
int j=n.length()-1;
while(i<j){
if(n.charAt(i)==n.charAt(j)){
i++;
j--;
continue;
}return false;
}return true;
}
public static NumberCategory checkAmicable(){
NumberCategory amicable=((number1,number2)->{
int n1=findFactor(number1);
int n2=findFactor(number2);
if(number1==n2 && number2==n1){
return true;
}
return false;
});
return amicable;
}
public static NumberCategory checkPalindrome(){
NumberCategory
palindrome=(((number1,number2)->isPalindrome(number1*number2)));
return palindrome;
}
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
int num1=Integer.parseInt(sc.nextLine());
int num2=Integer.parseInt(sc.nextLine());
boolean isAmicable=checkAmicable().checkNumberCategory(num1,num2);
boolean isPalindrome=checkPalindrome().checkNumberCategory(num1,num2);
if(isAmicable){
System.out.println("The numbers are amicable");
}
else{
System.out.println("The numbers are not amicable");
}
if(isPalindrome){
System.out.println("Product do produces a palindrome");
}
else{
System.out.println("Product does not produce a palindrome");
}
}
}