0

Test cases 3 and 5 failed. I don't think there is any bug in my code solution as per the Military Time CodeCoach question.

My code fails to qualify for test cases 3 and 5. I don't think there is any bug in my program. Someone please help ! My code solution for Military Time problem import java.util.*; import java.lang.*; import java.io.*; class MT { public static void main (String[] args) throws java.lang.Exception { Scanner sp = new Scanner(System.in); String mt = null; int i = 0; String m = sp.nextLine().toLowerCase(); if(m.indexOf(" am")!=-1) { if(Integer.parseInt(m.substring(0,m.indexOf(":")))==12) { mt ="00"+m.substring(m.indexOf(":"),m.indexOf(" ")); } else mt=m.substring(0,m.indexOf(" ")); } if(m.indexOf(" pm")!=-1) { if(Integer.parseInt(m.substring(0,m.indexOf(":")))==12) mt = m.substring(0,m.indexOf(" ")); else mt=Integer.toString(Integer.parseInt(m.substring(0,m.indexOf(":")))+12)+m.substring(m.indexOf(":"),m.indexOf(" ")); } System.out.println(mt); } }

29th Apr 2020, 9:34 AM
Wolf Master
Wolf Master - avatar
2 Respuestas
+ 1
Ok Understood thank You 😀
29th Apr 2020, 10:11 AM
Wolf Master
Wolf Master - avatar