'Java Program for Palindrome number
I write a program in java to find if a number is palindrome or not but I got a error which says execution timed out. I think there is a problem of infinite loop but did not get it that where this infinite loop present in my code and how it can be resolve. Please resolve this.
import java.io.*;
import java.lang.Math;
public class Test{
public static void main(String args[]){
double d = 0;
double b = Integer.MAX_VALUE;
double N = 12321;
double i = 0;
double c = 0;
double a = 0;
while(b > 10)
{
b = N/10;
d = d+1;
}
while(N >= 1)
{
c = Math.round(N%10);
a = a + c * Math.pow(10, d-i);
i++;
N = Math.round(N/10);
}
if(a == N)
{
System.out.print("Number is palindrome");
}
else
{
System.out.print("Number is not palindrome");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
