Skip to content

Commit

Permalink
Palindrome number
Browse files Browse the repository at this point in the history
  • Loading branch information
PRkudupu committed Jun 2, 2017
1 parent 69509df commit 14d0f97
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
Binary file added bin/Algorithms/Math/PalindromeNumber.class
Binary file not shown.
Binary file modified bin/Algorithms/Math/PerfectNumber.class
Binary file not shown.
Binary file modified bin/HomeMath.class
Binary file not shown.
16 changes: 16 additions & 0 deletions src/Algorithms/Math/PalindromeNumber.java
@@ -0,0 +1,16 @@
package Algorithms.Math;

public class PalindromeNumber {

public static boolean get(int x)
{
if (x<0 || (x!=0 && x%10==0)) return false;
int rev = 0;
while (x>rev){

rev = rev*10 + x%10;
x = x/10;
}
return (x==rev || x==rev/10);
}
}
5 changes: 1 addition & 4 deletions src/Algorithms/Math/PerfectNumber.java
Expand Up @@ -21,10 +21,7 @@ public static boolean get(int num)

for(int i=2;i<=Math.sqrt(num);i++)
{
if(num%i==0)
{
sum+=i;
}
if(num%i==0){sum+=i;}
if(i!=num/i) sum+=num/i;
}
sum++;
Expand Down
13 changes: 9 additions & 4 deletions src/HomeMath.java
Expand Up @@ -31,11 +31,16 @@ public static void main(String args[]){
Divisors of 6 are 1, 2 and 3. Sum of
divisors is 6.
*/

/*
boolean isPerfect =Algorithms.Math.PerfectNumber.get(8);
System.out.println(isPerfect);



*/
/**
* Input 12321 is a palindrome number
* Input 1231 is not a palindrome number
*/
boolean isPalindrome =Algorithms.Math.PalindromeNumber.get(12321);
System.out.println(isPalindrome);

}
}

0 comments on commit 14d0f97

Please sign in to comment.