Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reverse string and test

807600Sep 11 2007 — edited Sep 11 2007
I'm trying to write a program where a string is reversed and compared to the original to se if the string is a palindrome or not, can i get some help?
import java.util.Scanner;
public class PalindromeTest
{
   // main method begins execution of Java application
   public static void main( String args[] )
   {
      //create scanner to read user input
	  Scanner input = new Scanner( System.in );
	  
	  Palindrome myPalindrome = new Palindrome();
	  
	  String reversed;
	  
	  System.out.println( "Hello, please enter a word to be checked as a palindrome: " );// prompt
	  reversed = input.nextLine(); 
	  myPalindrome.reverseAndCompare( reversed );
      
	  
   } //end method main

   } //end class PalindromeTest
public class Palindrome
{
   public void reverseAndCompare( String reversed1 )
   {
	 System.out.println( new StringBuffer(reversed1).reverse() ); 
	 
	 reversed1.compareTo( new StringBuffer(reversed1).reverse() );
	 
	 
   } //end method main

   } //end class Palindrome
How do i get to the original with the reversed? Do i need to assign the reversed to a new variable? how?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2007
Added on Sep 11 2007
27 comments
436 views