Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main{
- static final int ASCII_SIZE = 256;
- static char getMaxOccuringChar(String str2){
- int count[] = new int[ASCII_SIZE];
- int len = str2.length();
- for (int i = 0; i < len; i++)
- count[str2.charAt(i)]++;
- int max = -1;
- char result = ' ';
- for (int i = 0; i < len; i++) {
- if (max < count[str2.charAt(i)]) {
- max = count[str2.charAt(i)];
- result = str2.charAt(i);
- }
- }
- return result;
- }
- public static void main(String[] args){
- String str = "IN A RIGHT TRIANGLE THE SQUARE OF THE HYPOTENUSE EQUALS THE SUM OF THE SQUARES OF THE LEGS";
- String str2 = str.toLowerCase();
- System.out.println("Max occurring character is: " +
- getMaxOccuringChar(str2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment