Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

ย 

History

History
History
29 lines (25 loc) ยท 1.46 KB

File metadata and controls

29 lines (25 loc) ยท 1.46 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import java.util.Scanner;
public class c1019 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in); // Scanner ๊ฐ์ฒด ์ƒ์„ฑ
//System.print("์—ฐ์›” ์ž…๋ ฅ : ");
String clock = scan.nextLine(); // ํ•œ ์ค„์„ ์ž…๋ ฅ๋ฐ›์Œ
String[] arr = clock.split("\\."); // split๋ฅผ ์“ธ ๋•Œ ๋ญ”๊ฐ€ ์ž‘๋™์„ ์•ˆ ํ•˜๋ฉด \\์„ ๋ถ™์—ฌ ๋ณด๋Š” ๋ฐฉ๋ฒ• ์ถ”์ฒœ.
int[] arr2 = new int[arr.length]; // ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋งŒํผ ์ •์ˆ˜ ๋ฐฐ์—ด ์„ ์–ธ
for(int i= 0; i < arr.length; i++){
arr2[i] = Integer.parseInt(arr[i]);
}
System.out.printf("%04d.%02d.%02d", arr2[0], arr2[1], arr2[2]); // ๋ถ„ํ•  ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅ
scan.close(); // ์ž…๋ ฅ ์ข…๋ฃŒํ›„ ์Šค์บ๋„ˆ ๋‹ซ์•„์ฃผ๊ธฐ
}
}
// ์ž…๋ ฅ ํด๋ž˜์Šค์ธ Scanner ๊ฐ์ฒด ์ƒ์„ฑ
// ๋‚ ์งœ ์ž…๋ ฅ์ด yyyy:mm:dd ํ˜•์‹์œผ๋กœ '.' ๊ตฌ๋ถ„๋˜์–ด ์ž…๋ ฅ๋œ๋‹ค.
// split() ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด '.'์„ ๊ตฌ๋ถ„ํ•˜์—ฌ String[], ๋ฌธ์ž์—ด ๋ฐฐ์—ด์— ๊ฐ๊ฐ ์ €์žฅ (๋ฌธ์ž์—ด์˜ ๊ธธ์ด : 3)
// ๋‚˜๋ˆ ์ง„ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด์— ๋งž์ถฐ int[], ์ •์ˆ˜ ๋ฐฐ์—ด arr2 ์ƒ์„ฑ (๊ฐ’์ด ์•„์ง ์ €์žฅ๋˜์ง€ ์•Š์Œ)
// for๋ฌธ์„ ํ†ตํ•ด arr์˜ ๊ธธ์ด(3)์— ๋งž์ถฐ ๋ฐ˜๋ณตํ•˜์—ฌ ๋ฌธ์ž์—ด์„ ์ •์ˆ˜ํ˜•ํƒœ๋กœ parsingํ•˜์—ฌ arr2์˜ ๋ฐฐ์—ด์— ์ €์žฅํ•œ๋‹ค.
// -> i=0, arr[0]์˜ ๊ฐ’์ด parsing ํ›„ arr2[0]์— ์ €์žฅ
// -> i=1, arr[1]์˜ ๊ฐ’์ด parsing ํ›„ arr2[1]์— ์ €์žฅ
// -> i=2, arr[2]์˜ ๊ฐ’์ด parsing ํ›„ arr2[2]์— ์ €์žฅ
// ๋ฐ˜๋ณต๋ฌธ ์ข…๋ฃŒ
// Scanner ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•œ ์ž…๋ ฅ์ด ์ข…๋ฃŒ๋˜์—ˆ์œผ๋ฏ€๋กœ ๊ฐ์ฒด ๋‹ซ๊ธฐ
Morty Proxy This is a proxified and sanitized view of the page, visit original site.