// code in java
class findPalindrome
{
public static void main(String[] args)
{
int num = 165;
System.out.println(findNumber(num));
}
static int findNumber(int num)
{
if(isPalindrome(num))
{
return num;
}
else
{
return findNumber(num + reverseNumber(num));
}
}
static int reverseNumber(int num)
{
int newNum = 0;
while(num > 0)
{
newNum = newNum*10 + num % 10;
num /= 10;
}
return newNum;
}
static boolean isPalindrome(int num)
{
return num == reverseNumber(num);
}
}
class findPalindrome
{
public static void main(String[] args)
{
int num = 165;
System.out.println(findNumber(num));
}
static int findNumber(int num)
{
if(isPalindrome(num))
{
return num;
}
else
{
return findNumber(num + reverseNumber(num));
}
}
static int reverseNumber(int num)
{
int newNum = 0;
while(num > 0)
{
newNum = newNum*10 + num % 10;
num /= 10;
}
return newNum;
}
static boolean isPalindrome(int num)
{
return num == reverseNumber(num);
}
}
No comments:
Post a Comment