PHP Code:
import java.util.Scanner;
public class CharOccurence {
public static void main(String[] arg){
Scanner input = new Scanner(System.in);
System.out.println("Enter a sentence to count the occurence of each letter");
String words=input.nextLine();
int[] count = letterOccurence(words.toLowerCase());
for(int i=0;i<words.length();i++){
if(count[words.charAt(i) - 'a'] == 1)
System.out.println(words.charAt(i)+ " occurence: "+ count[words.charAt(i) - 'a']+ " time");
else
System.out.println(words.charAt(i)+ " occurence: "+ count[words.charAt(i) - 'a']+ " times");
}
}
public static int[] letterOccurence(String sentence){
int[] count = new int[26];
for(int i=0;i<sentence.length();i++){
if(Character.isLetter(sentence.charAt(i)))
count[sentence.charAt(i) - 'a']++;
}
return count;
}
}