-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc1020.java
More file actions
24 lines (21 loc) ยท 1023 Bytes
/
Copy pathc1020.java
File metadata and controls
24 lines (21 loc) ยท 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class c1020 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in); // Scanner ๊ฐ์ฒด ์์ฑ
System.out.print("์ฃผ๋ฏผ๋ฒํธ ์
๋ ฅ : ");
String num = scan.nextLine(); // ํ ์ค์ ์
๋ ฅ๋ฐ์
String[] arr = num.split("-");
for(String a : arr){
System.out.print(a);
}
//System.out.printf(arr[0]+arr[1]);
scan.close(); // ์
๋ ฅ ์ข
๋ฃํ ์ค์บ๋ ๋ซ์์ฃผ๊ธฐ
}
}
// ์
๋ ฅ ํด๋์ค์ธ Scanner ๊ฐ์ฒด ์์ฑ
// 123456-1234567 ํ์์ผ๋ก '-' ๊ตฌ๋ถ๋์ด ์
๋ ฅ๋๋ค.
// split() ๋ฉ์๋๋ฅผ ํตํด '-'์ ๊ตฌ๋ถํ์ฌ String[], ๋ฌธ์์ด ๋ฐฐ์ด์ ๊ฐ๊ฐ ์ ์ฅ
// EnhancedLoop for๋ฌธ์ ์ด์ฉํ์ฌ arr์ ๊ฐ์ a์ ํ๋์ฉ ์ ์ฅํ๊ณ a๋ฅผ ์ถ๋ ฅํ๋ค.
// -> arr์ ๊ฐ์ด ์์ ๋๊น์ง for๋ฌธ์ด ๋ฐ๋ณต๋๋ค.
// -> ๋ฐฐ์ด์ ์ ์ฅ๋์ด์๋ ๋ฐ์ดํฐ ํ์
๊ณผ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ๋ณ์์ ํ์
์ด ๊ฐ์์ผํ๋ค.
// Scanner ๊ฐ์ฒด๋ฅผ ์ด์ฉํ ์
๋ ฅ์ด ์ข
๋ฃ๋์์ผ๋ฏ๋ก ๊ฐ์ฒด ๋ซ๊ธฐ