I found a way to fix my previous problem. But now I want to limit the decimal place to 2 places and make a variable for frequency.
Also instead of typing in one character to see its frequency, I want to see all letters occurence and frequencies and the program should stop when the user enters something other than a letter (no white space). Some how I keep getting compiler errors.
Thanks
import java.util.*;
import java.text.*;
public class GoodLetterCounter
{
public static void main(String[] args)
{
System.out.println("\n'This program will return how many times" +
" the character you entered showed up in" +
" the string you entered'.");
System.out.println("");
Scanner keyboard = new Scanner(System.in);
int charCount = 0;
String userString = new String();
float frequency = (charCount * 100/(userString.length()));
do
{
System.out.print("Please enter a string: ");
userString = keyboard.nextLine();
System.out.print("Now enter a character from the string: ");
char userChar = keyboard.nextLine().charAt(0);
for(int i= 0; i<userString.length();i++)
{
if (userString.charAt(i) == userChar)
{
charCount++;
}
}
System.out.println("\nThe character " +"\"" + userChar +
"\" appeared " + charCount+ " times." );
System.out.println("The frequency was " + frequency + "%");
System.out.println("");
} while (userString.length() != 0);
}
}