forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
22 lines (18 loc) · 964 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Problem: https://www.hackerrank.com/challenges/time-conversion
//Java 8
import java.io.*;
import java.util.*;
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 time = input.nextLine();
int hour = Integer.parseInt(time.substring(0,2));
int minute = Integer.parseInt(time.substring(3,5));
int second = Integer.parseInt(time.substring(6,8));
String meridiem = time.substring(8,10);
hour += ((meridiem.equals("PM") && hour != 12)?12:0);//Performs conversion based on current meridiem
hour -= ((meridiem.equals("AM") && hour == 12)?12:0);
System.out.println(String.format("%02d",hour) + ":" + String.format("%02d",minute) + ":" + String.format("%02d",second));
}
}