-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb003_String.java
More file actions
38 lines (32 loc) · 1.05 KB
/
Copy pathProb003_String.java
File metadata and controls
38 lines (32 loc) · 1.05 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
package java0904_api.prob;
/*
* 1 매개변수로 받은 문자열에서 각 단어의 첫 번째만
리턴하는 makeInitial 메서드를 구현하시오.
* 2 출력결과
* JDBC
* JSP
* EJB
*/
public class Prob003_String {
public static void main(String[] args) {
System.out.println(makeInitial("Java Data Base Conectivity"));
System.out.println(makeInitial("Java Server Pages"));
System.out.println(makeInitial("Enterprise Java Beans"));
}// end main()
private static String makeInitial(String fullName) {
// fullName의 매개변수에서 각 단어의 첫글자만
// 반환하는 프로그램을 구현하시오.
/*
* String[] array = fullName.split(" "); char[] arr = new char[array.length];
* for (int i = 0; i < array.length; i++) { arr[i] = array[i].charAt(0); }
* String data = new String(arr);
*/
String data = "";
for (int i = 0; i < fullName.length(); i++) {
if (i == 0 || fullName.charAt(i - 1) == ' ') {
data += fullName.charAt(i);
}
}
return data;
}// end makeInitial()
}// end class