//The Prompt is: Write a program that asks the user to enter a string, and //then ask the user to enter a character. The program should count and display //the number of times that the specified character appears in the string.
import java.util.Scanner;
public class LetterCounter{
Scanner keyboard = new Scanner (System.in); //Scanner
// Declare Variables
String userString; // String user entered
String userCharacter; // Character user entered
int StringSize;
// Ask the user to enter a string
System.out.println("Please Enter a String.");
userString = keyboard.nextLine();
// Ask the user to enter a charcter
System.out.println("Please Enter a Character.");
userCharacter = keyboard.nextLine();
// Count and display the number of times that character appears in the
// string chosen by the user.
int character;
character = Integer.parseInt(userCharacter);
StringSize = userString.charAt(character);
}
}
For some reason I can't get it to work, I just don't know where to go from here. Do I possibly need a FOR-LOOP?
Thanks for your help