-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClock.java
37 lines (30 loc) · 1.04 KB
/
Clock.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
26
27
28
29
30
31
32
33
34
35
36
37
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner input = new Scanner(System.in);
String inputTime = input.nextLine();
String [] tempArray = inputTime.split(":");
String hours = tempArray[0];
String minutes = tempArray[1];
String seconds = tempArray[2].substring(0, 2);
int tempHours;
if (tempArray[2].substring(2, 4).equalsIgnoreCase("PM")) {
if (Integer.parseInt(hours) < 12) {
tempHours = Integer.parseInt(hours);
tempHours += 12;
hours = Integer.toString(tempHours);
}
}
if (tempArray[2].substring(2, 4).equalsIgnoreCase("AM")) {
if (Integer.parseInt(hours) == 12) {
hours = "00";
}
}
System.out.println(hours + ":" + minutes + ":" + seconds);
}
}