-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockConversion.java
More file actions
42 lines (40 loc) · 1.3 KB
/
ClockConversion.java
File metadata and controls
42 lines (40 loc) · 1.3 KB
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
import java.util.Scanner;
public class ClockConversion {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for (int i = 0; i < t; i++) {
String s=sc.next();
StringBuilder res=new StringBuilder(s);
StringBuilder res2=new StringBuilder();
res2.append(s.charAt(0));
res2.append(s.charAt(1));
int a=Integer.parseInt(res2.toString());
if(a>=12) {
res.append(" PM");
if(a==12) System.out.println(res);
else {
a -= 12;
String x=String.valueOf(a);
if(a>9) {
res.setCharAt(0, x.charAt(0));
res.setCharAt(1, x.charAt(1));
}
else {
res.setCharAt(0,'0');
res.setCharAt(1, x.charAt(0));
}
System.out.println(res);
}
}
else{
if(a==0){
res.setCharAt(0, '1');
res.setCharAt(1, '2');
}
res.append(" AM");
System.out.println(res);
}
}
}
}