+ 1

Military time

Fourth case not passed .

16th Aug 2021, 5:35 PM
vicky
vicky - avatar
6 Antworten
+ 1
import java.util.Scanner; class date { public static void main(String[] args) { Scanner sn=new Scanner(System.in); String s1=sn.nextLine(); char[] a=s1.toCharArray(); char b=s1.charAt(5); char c=s1.charAt(6); // taking AM only if(c=='A'||b=='A') { int d=Character.getNumericValue(a[0]); int s=10+Character.getNumericValue(a[1]); int n1=s; if(12==n1) { System.out.print("00"); for(int k=2;k<5;k++) { System.out.print(a[k]); } } else{ for(int f=0;f<a.length;f++) { if(a[f]==':') { if((f-1)==0) { System.out.print("0"); for(int i=0;i<a.length-2;i++)
16th Aug 2021, 5:38 PM
vicky
vicky - avatar
+ 1
Try this: a=input() b=a.replace("AM","").replace ("PM","") ans="" if a[-2:]=="PM": if b[1]==":": ans=str(int(b[0])+12)+b[1:] elif b[0:2]== "12": ans="12"+b[2:] else: ans=str(int(b[0:2])+12)+b[2:] else: if b[1]==":": ans="0"+b[0:] elif b[0:2]=="12": ans="00"+b[2:] else: ans=b print(ans)
17th Aug 2021, 4:48 AM
Arun Jamson
Arun Jamson - avatar
0
See once
16th Aug 2021, 6:06 PM
vicky
vicky - avatar
0
vicky i am not sure if this is a right condition or not but for 00:15 PM it outputs 22:15 . Anyway i am sure there is nothing like 00:15 PM since i always hear 12:15 PM !!
16th Aug 2021, 7:39 PM
Abhay
Abhay - avatar
0
Abhay but you don't give input in terms of 24 hrs time ,soo if you give 12 AM or 12 PM it should show in 24 hrs format
17th Aug 2021, 3:03 AM
vicky
vicky - avatar