I will post my whole code again so we're all on the same page lol
import java.util.Scanner; public class LetterDriver { public static void main(String[] args){ System.out.println("Enter lines of text, type two returns in a row to end."); Scanner scan = new Scanner(System.in); String tScan= " "; while(tScan.length() > 0) // while the length of the line is longer than 0 { tScan = scan.nextLine(); // read the next line } LetterProfile k = new LetterProfile(); k.printResults(); } }
public class LetterProfile { int scoreboard[] = new int [26]; private int index; private int next; private int largest =0; private int largestindex =0; public void countChars (String s) { // changes the input text to lower case letters s = s.toLowerCase(); // char a = 'a'; for (int i =0;i < s.length();i++) { int next = (int)s.charAt(i)-(int) a; if ( next<26 && next >= 0) scoreboard[next]++; } } public void scoreLine (String line) { int index = line.length(); for (int j = 0; j<index; j++) { scoreboard[j]++; System.out.println(j + scoreboard[j]); } } public int largestLength() { int largest = 0; int largestindex = 0; for(int a = 0; a<26; a++) { if(scoreboard[a]>largest) largest = scoreboard[a]; largestindex = a; } return (char)largestindex; } public int printResults() { largestLength(); return largestLength(); } }
--- Update ---
scoreLine is supposed to print out the letter and the number of times that letter appeared.