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 we call the Thread.sleep in Synchyronozed block?

5 Answers   Logica CMG,


Why java doesn’t support multiple inheritances?

0 Answers  


What is string :: npos?

0 Answers  


What Is Composition?

0 Answers   IBS,


write a class to input 2 points by the user & check the line maked by the points is horizontal,vertical or rectangle?

1 Answers  


What does string intern() method do?

0 Answers  


Is arraylist an object in java?

0 Answers  


what should do when using multiple catch() block & what should never do for the same?

1 Answers  


What do you mean by buffering?

0 Answers  


What is the equal sign?

0 Answers  


How can you generate random numbers in java?

0 Answers  


What is type safety in java?

0 Answers  


Categories