•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 427,851 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,729 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2717 | Replies: 1
![]() |
•
•
Join Date: Sep 2004
Location: Yorkshire, England
Posts: 17
Reputation:
Rep Power: 5
Solved Threads: 0
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
any help and advice would be appeciated i have to submit my course work in two weeks and have an exam on this stuff
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
Last edited by alc6379 : Nov 29th, 2004 at 2:51 pm. Reason: added [code] tags
:p
If you worry you Die.
If you dont worry you Die.
SO DONT WORRY
:cool:
If you worry you Die.
If you dont worry you Die.
SO DONT WORRY
:cool:
•
•
Join Date: Nov 2004
Posts: 10
Reputation:
Rep Power: 4
Solved Threads: 0
When you use .hasMoreTokens(), it returns a value and it seem to be that you aren't doing anything with this value - "while ( tTokens.hasMoreTokens() )" - so the while() never knows what is being satisfied or not. You need to make a condition in a while statement. Look up what kind of value the .hasMoreTokens() returns and you should be able to fix this.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Tokeniser (C++)
- Txt Coordinates into chart... (Java)
- Java's String Tokenizer (Java)
Other Threads in the Java Forum
- Previous Thread: paint() in java awt
- Next Thread: Panel Layouts


Linear Mode