Write the code for Palindrome ?

Answers were Sorted based on User's Feedback



Write the code for Palindrome ?..

Answer / aslam

public boolean isPaliandrome(String txtToCheck){

StringBuffer strb1 = new StringBuffer(txtToCheck).reverse();
if(txtToCheck.equals(strb1.toString()))
return true;
return false;

}

Is This Answer Correct ?    5 Yes 4 No

Write the code for Palindrome ?..

Answer / suresh royal

mport java.io.*;

public class Palindrome {
public static void main(String [] args){
try{
BufferedReader object = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter number");
int num= Integer.parseInt(object.readLine());
int n = num;
int rev=0;
System.out.println("Number: ");
System.out.println(" "+ num);
for (int i=0; i<=num; i++){
int r=num%10;
num=num/10;
rev=rev*10+r;
i=0;
}
System.out.println("After reversing the number: "+ " ");
System.out.println(" "+ rev);
if(n == rev){
System.out.print("Number is palindrome!");
}
else{
System.out.println("Number is not palindrome!");
}
}
catch(Exception e){
System.out.println("Out of range!");
}
}
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

Can inner class final?

0 Answers  


which class to use when concatenating strings in a loop.

3 Answers   IBM,


Is java hard to learn?

0 Answers  


What are assertions in java?

1 Answers   Impetus,


Which class is the superclass for every class in java programming?

0 Answers  






Can a final variable be initialized in constructor?

0 Answers  


Is 'null' a keyword?

8 Answers  


How to sort the elements in HashMap

3 Answers   Ness Technologies,


how to make hashmap object as synchronized object?

2 Answers   BOB Technologies,


What is compareto () in java?

0 Answers  


Explain the use of volatile field modifier?

0 Answers  


what is meant by package in java?

5 Answers  


Categories