Write a program that inputs a 5-digit integer from the
keyboard and prints if the input number is a palindrome or
not. A palindrome is a number which has the same digit from
either end.
Answer Posted / vinit
import java.io.*;
public class HelloWorld{
public static void main(String []args)throws IOException{
//System.out.println("Hello World");
int n;
int t;
int cpy;
int r,rev;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
t=Integer.parseInt(br.readLine());
while(t!=0)
{rev=0;
n=Integer.parseInt(br.readLine());
cpy=n;
while(n!=0)
{
r=n%10;
n=n/10;
rev=(rev*10)+r;
}
if(rev==cpy)
{System.out.println("palindrome");
t--;
continue;}
else{
System.out.println("not Palindrome");t--;
continue;
}
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How can we establish connection with java and sql server?
What is javascript and its advantages?
How would you compare two objects in JavaScript?
Are javascript variables global?
How can you to add javascript to a page when performing an asynchronous postback?
How do I open javascript on my iphone?
What is Number object in JavaScript?
How to convert json string to object?
What is the use of the ‘this’ keyword?
Explain the difference between javascript and an asp script.
How can javascript make a web site easier to use? That is, are there certain javascript techniques that make it easier for people to use a web site?
What is design pattern in javascript? Explain
What is the function of javascript?
What is enum data type?
Why do we need to declare variables?