-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeConvert.java
More file actions
28 lines (23 loc) · 837 Bytes
/
TimeConvert.java
File metadata and controls
28 lines (23 loc) · 837 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
25
26
27
// https://www.hackerrank.com/challenges/time-conversion
import java.util.*;
public class TimeConvert {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String[] time = sc.nextLine().split(":");
String hours = time[0];
String minutes = time[1];
String seconds = time[2].substring(0,2);
String dayEve = time[2].substring(2,4);
if(dayEve.equals("AM"))
{
//used Conditional Operator ( ? : )
//http://www.tutorialspoint.com/java/java_basic_operators.htm
System.out.println((hours.equals("12")?"00":hours) +":"+minutes+":"+seconds);
}
else
{
System.out.println((hours.equals("12")?hours:(Integer.parseInt(hours)+12))+":"+minutes+":"+seconds);
}
}
}