View Single Post
  #1 (permalink)  
Old 11-14-2007, 08:25 PM
jpnym15 jpnym15 is offline
Member
 
Join Date: Nov 2007
Posts: 19
jpnym15 is on a distinguished road
I am completely stuck
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"); } }
That is my program...how would i go about finding the searchword, and also finding how many times it is found in the sentence.

Last edited by JavaBean : 11-14-2007 at 08:38 PM.
Reply With Quote
Sponsored Links