- Notifications
You must be signed in to change notification settings - Fork 846
/
Copy path2.java
25 lines (20 loc) · 689 Bytes
/
2.java
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
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
Stringstr = sc.next();
// 첫 번째 문자를 숫자로 변경한 값을 대입
longresult = str.charAt(0) - '0';
for (inti = 1; i < str.length(); i++) {
// 두 수 중에서 하나라도 '0' 혹은 '1'인 경우, 곱하기보다는 더하기 수행
intnum = str.charAt(i) - '0';
if (num <= 1 || result <= 1) {
result += num;
}
else {
result *= num;
}
}
System.out.println(result);
}
}