eg: 1221 palindrome no, 123 not a palindrome ..
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author pankaj
*/
public class palindrome {
public static void main(String[] args)
{
try {
System.out.print("enter a no to check weather it si a palindrome or not : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String num=br.readLine();
int no=Integer.parseInt(num);
int temp=no;
int digit=0,ld;
while(no!=0)
{
ld=no%10;
digit=digit*10+ld;
no=no/10;
}
if(temp==digit)
{
System.out.print("Palindrome no");
}
else
System.out.print("Not a palindrome no");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author pankaj
*/
public class palindrome {
public static void main(String[] args)
{
try {
System.out.print("enter a no to check weather it si a palindrome or not : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String num=br.readLine();
int no=Integer.parseInt(num);
int temp=no;
int digit=0,ld;
while(no!=0)
{
ld=no%10;
digit=digit*10+ld;
no=no/10;
}
if(temp==digit)
{
System.out.print("Palindrome no");
}
else
System.out.print("Not a palindrome no");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
No comments:
Post a Comment