lundi 23 février 2015

Java: String variable counter algorithm

Has anyone written any algorithms that can thread through strings and pick out words that are assigned a specific value? For example:



Scanner keyboard = new Scanner(System.in);

String sentence = "";
sentence = keyboard.nextInt();
System.out.println("Type a sentence");

//Below are incorrect words
int teh, cwo, og, wirte;
teh = cwo = og = wirte = spelledWrong;

//Want to return number of instances spelledWrong occurs


So here we have a few incorrectly spelled words and when we type perhaps:


teh cwo og to school


instead of


the cow go to school


we want the program to return that there are three instances of misspelled words.


I've looked all over the forums for the satisfactory result. I'll be very happy if someone can assist or point me in the right direction!


Aucun commentaire:

Enregistrer un commentaire