Write a Java program with three (3) static methods that implements this algorithm:
a.Method 1: Ask the user to enter a sentence. Get the String input by using class Scanner method nextLine(). (Note: do not use method next(), or you will only get the first word.) Store the sentence as a String in a local variable. Return the local variable (the sentence) to the main method.
b.Method 2: the parameter to this method is the sentence (a String variable). Declare an array of 26 integers. Use a for loop to loop through each character in the sentence. Use the String method charAt(position) to get each character from the sentence. If the character is a letter, increment the corresponding array element. For example, the letter a corresponds to the first element in the array of integers. The letter b corresponds to the second element in the array of integers. Return the array of integers to the main method. The array of integers should contain the frequency count for each letter.
c.Method 3: The parameter to this method is the array of integers, which is the frequency count. Output the frequency count to the screen.
import java.util.*;
public class Frequency {
public String str;
public char ch;
public static void main(String[] args) {
String str;
Scanner input = new Scanner(System.in);
System.out.print("Enter a sentence: ");
str = input.nextLine().toLowerCase();
}
int freq [] = new int[26];{
for(int i = 0; i < str.length(); i ++) {
char ch = str.charAt(i);
if(ch>= 'a' && ch<= 'z'){
freq[ch - 'a']++;
}
for (int j =0; j <26; j++){
System.out.println("Frequency of each letter: ");
System.out.println((char)(i+'a') +" = " + freq[i]);
}
}