728x90
반응형
package chap6;
/*
String str =
"it is possible to draw a parallel between their experience and ours";
소문자로 이루어진 문자열의 알파벳의 사용 횟수를 출력하기
[결과]
a:5개
b:2개
c:1개
d:2개
...
*/
public class Test0310_1 {
public static void main(String[] args) {
String str = "it is possible to draw a parallel between their experience and ours";
int[] arr= new int[26];
for(int i=0;i<str.length();i++) {
char ch = str.charAt(i);
if(ch >= 'a' && ch <= 'z') {
arr[ch-'a']++;
}
}
for(int i=0;i<arr.length;i++) {
System.out.println((char)(i+'a') + ":" + arr[i] + "개");
}
}
}
728x90
반응형
'study > Java' 카테고리의 다른 글
[Java] 18. TEST3 풀이 (구동 클래스가 다음과 같을때 Card 클래스를 완성하시오) (0) | 2022.03.17 |
---|---|
[Java] 18. TEST2 풀이 (다음의 결과가 나오도록 삼각형의 높이를 작성하시오) (0) | 2022.03.17 |
[Java] 18. TEST5 (다음 결과가 출력되도록 동물클래스(Animal)와 구동클래스(Test0310_5)를 구현하기 ) (0) | 2022.03.17 |
[Java] 18. TEST4 (Rectangle2 클래스 구현하기 / 구동클래스에 Rectangle2 클래스의 객체를 5개 생성하기) (0) | 2022.03.17 |
[Java] 18. TEST3 (구동 클래스가 다음과 같을때 Card 클래스를 완성하시오) (0) | 2022.03.17 |