-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.java
40 lines (30 loc) · 797 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package basicLevel1042;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// use string to hold the input
String string = in.nextLine();
// create a array which length is 26
int[] array = new int[26];
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (c >= 'a' && c <= 'z') {
array[c - 'a']++;
} else if (c >= 'A' && c <= 'Z') {
array[c - 'A']++;
} else {
//except character
//like number, coin sign and other letters.
}
}
in.close();
int maxIndex = 0;
for (int i = 1; i < array.length; i++) {
if (array[i] > array[maxIndex]) {
maxIndex = i;
}
}
System.out.println((char)(maxIndex + 'a') + " " + array[maxIndex]);
}
}