-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
23 lines (20 loc) · 815 Bytes
/
Solution.java
File metadata and controls
23 lines (20 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;
public class Solution {
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
String s = scan.nextLine();
System.out.println(timeConversion(s));
scan.close();
}
static String timeConversion(String s) {
StringBuilder sb = new StringBuilder();
if (s.substring(8).equalsIgnoreCase("PM") && !s.startsWith("12")) {
sb.append((Integer.parseInt(s.substring(0, 2))) + 12);
sb.append(s, 2, 8);
} else if (s.substring(8).equalsIgnoreCase("AM") && s.startsWith("12")) {
sb.append(String.format("%02d", Integer.parseInt(s.substring(0, 2)) - 12));
sb.append(s, 2, 8);
} else sb.append(s, 0, 8);
return sb.toString();
}
}