I am trying to write a program that asks the user to enter a string and then asks the user to enter a character. The program is supposed to count and display the number of times that the specified character appears in the string.
So far my code is:
import java.util.Scanner; // Needed for the Scanner class
public class LetterCounter
{
public static void main(String[] args)
{
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
String string;
char character;
System.out.print("Please enter a string: ");
string = keyboard.nextLine();
System.out.print("Please enter a character: ");
character = keyboard.nextchar();
int letter = string.charAt(character);
System.out.println ("The character " + character +
"appears in your sting" + letter +
" times.");
}
}
The error says "Cannot find symbol method nextchar()"
I also am unsure of how to count the times a character appears in a string.
Any help would be highly appreciated.