Results 1 to 3 of 3
Thread: I am completely stuck
- 11-14-2007, 06:25 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 19
- Rep Power
- 0
I am completely stuck
That is my program...how would i go about finding the searchword, and also finding how many times it is found in the sentence.Java Code:public class StringSearcher { public static void main (String[] args) { java.util.Scanner userInput = new java.util.Scanner(System.in); String sentence = new String(); String searchword = new String(); int sentenceLength; int wordLength; int wordIndex; int total = 0; int index; index = sentence.indexOf(" "); while(index != -1) { total++; index = sentence.indexOf("searchword", index + 1); } System.out.println("Enter a sentence."); sentence = userInput.nextLine(); System.out.println("Now enter a search word."); searchword = userInput.nextLine(); System.out.println("Your sentence had the search word "+searchword+"+total+" times"); } }Last edited by JavaBean; 11-14-2007 at 06:38 PM.
- 11-14-2007, 06:38 PM #2
jpnym15, please learn to use [code] block for your codes: http://www.java-forums.org/misc.php?do=bbcode
- 11-14-2007, 06:40 PM #3
Similar Threads
-
musically stuck cry for help 2
By geork in forum New To JavaReplies: 0Last Post: 02-07-2008, 02:09 PM -
musically stuck
By geork in forum New To JavaReplies: 1Last Post: 02-06-2008, 09:44 PM -
Stuck and Frustrated.
By jazzinspace in forum New To JavaReplies: 7Last Post: 01-12-2008, 02:38 PM -
Files not completely deleted on Linux
By amamare in forum Advanced JavaReplies: 0Last Post: 12-19-2007, 02:12 PM -
hi there i am stuck with a construct can anyone help???
By sonal in forum New To JavaReplies: 3Last Post: 12-05-2007, 02:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks