-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindChar.java
More file actions
52 lines (39 loc) · 1.24 KB
/
Copy pathFindChar.java
File metadata and controls
52 lines (39 loc) · 1.24 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
package algorithm.text;
import java.util.Scanner;
/*
1. 문자 찾기
설명
한 개의 문자열을 입력받고, 특정 문자를 입력받아 해당 특정문자가 입력받은 문자열에 몇 개 존재하는지 알아내는 프로그램을 작성하세요.
대소문자를 구분하지 않습니다.문자열의 길이는 100을 넘지 않습니다.
입력
첫 줄에 문자열이 주어지고, 두 번째 줄에 문자가 주어진다.
문자열은 영어 알파벳으로만 구성되어 있습니다.
출력
첫 줄에 해당 문자의 개수를 출력한다.
예시 입력 1
Computercooler
c
예시 출력 1
2
*/
public class FindChar {
public int solution(String str, char t) {
int answer = 0;
str = str.toUpperCase();
t = Character.toUpperCase(t);
/*for(int i=0; i < str.length(); i++){
if(str.charAt(i) == t) answer++;
}*/
for (char c : str.toCharArray()) {
if (c == t) answer++;
}
return answer;
}
public static void main(String[] args) {
FindChar T = new FindChar();
Scanner sc = new Scanner(System.in);
String str = sc.next();
char c = sc.next().charAt(0);
System.out.println(T.solution(str, c));
}
}