import java.util.Scanner; public class FindWord { public static void main (String[] args) { Scanner scanInput; scanInput = new Scanner(System.in); String search, word; int count; word = "hi"; count = 0; System.out.print("Enter a search word: "); search = scanInput.next(); while(!(word.equals("stop"))) { System.out.print("Enter a word, type 'stop' to halt: "); word = scanInput.next(); if (word.equals(search)); count++; System.out.println(search + " appears " + count + " time "); } }//main }//end of class
When i run the program i get this output:
Enter a search word: computer
Enter a word, type 'stop' to halt: dog
computer appears 1 time
Enter a word, type 'stop' to halt: rac
computer appears 2 time
Enter a word, type 'stop' to halt: thing
computer appears 3 time
Enter a word, type 'stop' to halt:
idk why it keeps counting computer after every word i enter
im supposed to receive this code:
computer appears 1 time
computer appears 1 time when case does not match
1 word starts with the same letter as computer
1 word starts with the same letter as computer but the opposite case
1 word has computer somewhere in the word
Thanks.