I am trying to write a for loop in Java that will count the occurrences of a letter in a string. The user will enter the letter to count and the string in which to search. This
your Scanner class has not moved to the next line after reading the character
letter = in.next().charAt(0);
add another in.nextLine() before reading the input string
System.out.println("Enter a character for which to search");
letter = in.next().charAt(0);
in.nextLine();
System.out.println("Enter the string to search");
sentence = in.nextLine();
old thread but hope this helps :)