Hi i have written a program to reconise palendromes in a sentance. I have written a method to reverse a word but dont know how to get the string tokeniser to reconise the words in a sentance. could any one give me some advice on how to use HasMoreTokens
this is the code i have written so far
//filename Palindrome.java
//created Monday 15th nov 2004
// Finds Palindromes in a sentance
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Palindrome
{
public static void main(final String[] pArgs) throws IOException
{
final InputStreamReader tInputStreamReader = new InputStreamReader(System.in);
final BufferedReader tKeyboard = new BufferedReader(tInputStreamReader);
// get user to input a sentance
System.out.println(" A Palindrome is a word that is spelt the same way backwards i.e bob. dad, abba");
System.out.println();
System.out.println(" Please Type in a Sentance with some Palindromes in it ");
System.out.flush();
final String tLine1 = tKeyboard.readLine();
// takes words and splits them into separate strings
final StringTokenizer tTokens = new StringTokenizer (tLine1, " ");
final String tWord1 = tTokens.nextToken();
while ( tTokens.hasMoreTokens() )
{
final String tWord = tTokens.nextToken();
}
}
public static boolean iPalindrome (final String pWord1)
{
final int tStringLength = pWord1.length();
for (int tCharNumber = tStringLength -1; tCharNumber >=0; tCharNumber--)
{
System.out.print(pWord1.charAt(tCharNumber));
}
return true;
//System.out.println();
}
// end method
}
any help and advice would be appeciated i have to submit my course work in two weeks and have an exam on this stuff