java palindrome help

Posted by jdbeverly87 on Stack Overflow See other posts from Stack Overflow or by jdbeverly87
Published on 2010-04-17T01:36:01Z Indexed on 2010/04/17 1:43 UTC
Read the original article Hit count: 545

Filed under:
|
|
|
|

I'm creating a program that checks if a word or phrase is a palindrome. I have the actual "palindrome tester" figured out. What I'm stuck with is where and what to place in my code to have the console read out "Enter palindrome..." and then text. I've tried with IO but it doesnt work out right. Also, how do I create a loop to keep going? This code only allows one at a time `public class Palindrome {

public static void main(String args[]) {  
  String s="";  
  int i;  
  int n=s.length(); 
  String str="";  

  for(i=n-1;i>=0;i--)  
   str=str+s.charAt(i);  

  if(str.equals(s))  
   System.out.println(s+ " is a palindrome");  

  else  System.out.println(s+ " is not a palindrome"); }

}

© Stack Overflow or respective owner

Related posts about java

Related posts about palindrome