-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimeConversion.java
46 lines (33 loc) · 1.13 KB
/
TimeConversion.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
38
39
40
41
42
43
44
45
46
package warmup;
import java.util.Scanner;
/**
* Created by tatarJR on 3/8/2017.
*/
public class TimeConversion {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String time = in.next();
int hourDigits = Integer.parseInt(time.substring(0, 2));
String noonIndıcator = time.substring(8, 10);
//System.out.println(hourDigits);
//System.out.println(noonIndıcator);
String hourString = Integer.toString(hourDigits);
if (noonIndıcator.equals("AM")) {
if (hourDigits == 12) {
hourDigits = 0;
hourString = "0" + Integer.toString(hourDigits);
}
if(hourDigits < 10) {
hourString = "0" + Integer.toString(hourDigits);
}
} else if(noonIndıcator.equals("PM")) {
if (hourDigits < 12) {
hourDigits += 12;
hourString = Integer.toString(hourDigits);
} else{
}
}
String convertedTime = hourString + time.substring(2, 8);
System.out.println(convertedTime);
}
}