-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava122_String.java
More file actions
41 lines (32 loc) · 1.03 KB
/
Copy pathJava122_String.java
File metadata and controls
41 lines (32 loc) · 1.03 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
package java0904_api;
/*
* [출력결과]
* 35276은 숫자입니다.
* 2_8a은 문자입니다.
*/
public class Java122_String {
public static void main(String[] args) {
System.out.print("35276은 ");
prnDisplay(numCheck("35276"));
System.out.print("2_8a은 ");
prnDisplay(numCheck("2_8a"));
}// end main( )
public static boolean numCheck(String data) {
// data값이 숫자면 true 아니면 false을 반환하는 로직 구현
/*
* char[] carr = data.toCharArray(); for (int i = 0; i < carr.length; i++) { if
* (!(carr[i] < '9' & carr[i] > '0')) { return false; } }
*/
for (int i = 0; i < data.length(); i++) {
if (!(data.charAt(i) >= '0' && data.charAt(i) < '9')) {
return false;
}
}
return true;
}// end numCheck()
public static void prnDisplay(boolean chk) {
// chk값이 true이면 "숫자입니다."
// chk값이 false이면 "문자입니다." 로 출력하는 로직구현
System.out.println(chk ? "숫자입니다." : "문자입니다.");
}// end prnDisplay()
}// end class