Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-27-2007, 05:34 AM
Member
 
Join Date: Jul 2007
Posts: 18
jason27131 is on a distinguished road
I need help on my code
im trying to make a program that takes a string. Then, the user enters a word, and the program will search the previous string for the word. If the word is in the string, it will say Word found. If the word isn't in the string, it will say word not found.
Right now though, the program will only read the first word of the sentence. If i entered "jason was here", it will only read the jason. how do i make the program read the whole string?


CODE:

import java.util.*;
import javax.swing.*;
import java.io.*;

public class Strtok{

public static void main(String[] args){
String demo = JOptionPane.showInputDialog (null, "Please enter a String", "Enter String", JOptionPane.QUESTION_MESSAGE);
String word = JOptionPane.showInputDialog (null, "Please enter the word you are looking for", "Find", JOptionPane.QUESTION_MESSAGE);

StringTokenizer st = new StringTokenizer(demo);




if((st.nextToken()).equals (word)){
JOptionPane.showMessageDialog (null, "Yes, the word is in the String", "Word is found!", JOptionPane.INFORMATION_MESSAGE);
}

else{
JOptionPane.showMessageDialog (null, "No, the word isn't in the String", "Word is not found!", JOptionPane.INFORMATION_MESSAGE);
}


}
}

some help would be really nice.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-27-2007, 12:07 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Have u tried using another String reader class?
Buffered reader maybe?
Seems like it stop readeing when it finds the space
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-28-2007, 12:08 AM
Member
 
Join Date: Jul 2007
Posts: 18
jason27131 is on a distinguished road
im not advanced yet. how do i run two classes at the same time if i was to make a string reader class with this class. Or do you mean turn this class into a bufferReader class.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-28-2007, 12:19 AM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
You need to do something like this:
Code:
boolean found = false; while (st.hasMoreElements()) { if (st.nextToken().equals(word)) found = true; } if (found) //say it was found else //say it was not found
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-28-2007, 05:23 AM
Member
 
Join Date: Jul 2007
Posts: 18
jason27131 is on a distinguished road
thank you very much!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help fixing my code.. or non code? MrHuggykins New To Java 1 03-19-2008 11:12 PM
Pls some one to help mi wit this code _nik_ New To Java 3 02-10-2008 03:02 AM
tic tac toe code zoe New To Java 1 07-23-2007 05:36 PM
Need help with my code. stormviper New To Java 0 07-12-2007 04:18 PM
Generating Code Automatically Using Custom code Template In Eclipse JavaForums Eclipse 1 04-26-2007 04:52 PM


All times are GMT +3. The time now is 10:26 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org