Created
August 10, 2017 18:19
-
-
Save jorovipe97/995f1a34156fd57eec9b01fd4c19649c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class Solution { | |
static String timeConversion(String s) { | |
// Complete this function | |
int arrlength = 4; | |
int dateArrLength = 3; | |
String res; | |
int dateArr[] = new int[3]; | |
String dataArr[] = new String[4]; | |
dataArr = s.split(":"); | |
for (int i = 0; i < dateArrLength-1; i++) { | |
dateArr[i] = Integer.parseInt(dataArr[i]); | |
} | |
dateArr[2] = Integer.parseInt(dataArr[2].substring(0, 2)); | |
if (dataArr[2].substring(2, 4).equals("PM")) { | |
if (dateArr[0] == 12) | |
dateArr[0] = 0; | |
else | |
dateArr[0] += 12; | |
} | |
res = dateArr[0]+":"+dateArr[1]+":"+dateArr[2]; | |
return res; | |
} | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
String s = in.next(); | |
String result = timeConversion(s); | |
System.out.println(result); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment