|
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.
|