-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApplication.java
More file actions
53 lines (47 loc) · 1.65 KB
/
Application.java
File metadata and controls
53 lines (47 loc) · 1.65 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
53
package calculator;
import java.util.Scanner;
import java.util.Vector;
public class Application {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Vector<Integer> number = new Vector<>();
String words;
char custom;
// 문자열 입력
System.out.println("덧셈할 문자열을 입력해 주세요.");
words = sc.next();
// 커스텀 구분자 확인
if(words.charAt(0)=='/' && words.charAt(1)=='/' && words.charAt(3)=='\\' && words.charAt(4)=='n') {
custom = words.charAt(2);
// 숫자와 문자 분리
for(int i=5; i<words.length(); i++) {
char word = words.charAt(i);
if(word >= 48 && word <= 57) {
number.add(word-48);
}
else if(word != custom) {
// 예외 처리를 위한 예비출력
System.out.println("예외");
}
}
}
else { // 기본 구분자의 숫자와 문자 분리
for(int i = 0; i < words.length(); i++) {
char word = words.charAt(i);
if(word >= 48 && word <= 57) {
number.add(word-48);
}
else if(word != ',' && word != ':') {
// 예외 처리를 위한 예비출력
System.out.println("예외");
}
}
}
// 숫자의 합 출력
int sum = 0;
for(int i = 0; i < number.size(); i++) {
sum += number.get(i);
}
System.out.println(sum);
}
}