Here is my code:
import java.util.*;
public class LetCount
{
public static final int NUMCHARS = 27; //You define
// int addr(char ch) returns the equivalent integer address for the letter
// given in ch, 'A' returns 1, 'Z' returns 26 and all other letters return
// their corresponding position as well.
public static int addr(char ch)
{
return (int) ch - (int) 'A' + 1;
}
// Required method definitions for (1) analyzing each character to update
// the appropriate count; (2) determining most frequent letter;
// (3) determining least frequent letter; and (4) printing final results
// should be defined here.
public static char getCharValue(int index)
{
char character;
int intValueOfA = Character.getNumericValue('A');
for (index = 1; index <= NUMCHARS; index++)
{
int intValueOfChar = intValueOfA + index-1;
character = (char) intValueOfChar;
}
return character;
}
public static void countLetters(int count[], String line)
{
for (int lineIndex = 0; lineIndex < line.length(); lineIndex++)
{
char letter = line.charAt(lineIndex);
int arrayIndex = addr(letter);
count[arrayIndex] = count[arrayIndex] + 1;
}
}
public static char findMostFrequent (int [] count)
{
int biggestCount = 0;
int biggestCountIndex = 0;
for (int arrayIndex = 1; arrayIndex <= NUMCHARS; arrayIndex++)
{
if (count[arrayIndex] > biggestCount)
{
biggestCount = count[arrayIndex];
biggestCountIndex = arrayIndex;
}
}
return getCharValue(biggestCountIndex);
}
public static char findLeastFrequent(int [] count)
{
int smallestCount = 0;
int smallestCountIndex = 0;
for (int arrayIndex = 1; arrayIndex <= NUMCHARS; arrayIndex++)
{
if (count[arrayIndex] < smallestCount)
{
smallestCount = count[arrayIndex];
smallestCountIndex = arrayIndex;
}
}
return getCharValue(smallestCountIndex);
}
public static void printResults(int [] count)
{
for (int arrayIndex = 1; arrayIndex <= NUMCHARS; arrayIndex++)
{
System.out.println(getCharValue(arrayIndex) + " occurred " + count[arrayIndex] + " times.");
}
System.out.println();
System.out.println("Most frequent letter = " + findMostFrequent(count[]));
System.out.println("Least frequent letter = " + findLeastFrequent(count[]));
}
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in); // for reading input
int[] count = new int [NUMCHARS]; // count of characters
String line; // holds input line
// Other declarations as needed
//initializes all elements of count[] array to 0
for(int i=0; i<NUMCHARS; i++)
{
count=0;
}
// Method calls and other statements to complete problem solution go here
while (keyboard.hasNext())
{
line = keyboard.nextLine();
System.out.println(line);
countLetters(count[], line);
}
printResults();
}
}The error from the compiler occurs at the following lines:
System.out.println("Most frequent letter = " + findMostFrequent(count[]));System.out.println("Least frequent letter = " + findLeastFrequent(count[]));countLetters(count[], line);Please help! How do I change these lines so that the "'.class' expected" error is solved?