need help in my code,
February 21, 2008 at 6:52 AM
that my code....pleese i need help in my while and do....
import apcslib.*; import chn.util.*;
public class Palindrome { String sentence; String reverse;
public Palindrome () { sentence =""; reverse =""; } public void start() { getInput (); reverseInput (); compareSens (); } public void getInput() { System.out.println("Welcome To PALINDROME"); ConsoleIO console = new ConsoleIO(); System.out.print("Please enter your sentence "); sentence = console.readLine(); sentence = sentence.toLowerCase(); System.out.println("Your sentence is " + sentence); }
public void reverseInput () { String temp = sentence.trim(); System.out.println("Your trim sentence is "+ temp); int senLength=temp.length(); System.out.println("Length of the sentence is "+ senLength); int n = temp.indexOf(" "); System.out.println("The first white space is at "+n); while (senLength>0) { temp=temp=temp.substring(0,n); temp=temp.substring(n+1,temp.length()); System.out.println("The second white space is at " + temp); reverse=reverse+sentence.charAt(senLength-1); senLength--; } System.out.println("The reverse is " + reverse); } public void compareSens () { if (sentence.equals(reverse)) System.out.println("The sentence is a palindrome"); else System.out.println("The sentence is not a palindrome"); } }