Good Afternoon I've a piece of code that will count and display the occurrences of each of the letters of the alphabet from user input. But I need to put it in alphabetical order and display the most frequently occurring letter and the number of occurrences for that letter:
package Assessment2;
import java.util.Scanner;
public class test2 {
String str = "Hello World", s = str;
int count = 0;
public void show() {
Scanner input = new Scanner(System.in);
System.out.print("Enter String: ");
String s = input.nextLine();
System.out.println("****************************");
while (s.length() > 0) {
count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == s.charAt(0))
count++;
}
System.out.println(s.charAt(0) + ": " + count);
s = s.replace(String.valueOf(s.charAt(0)), "");
}
}
public static void main(String[] ar) {
new test2().show();
}
}