8th Jun 2021, 5:53 AM
Atul [Inactive]
10 Answers
+ 2
Unable to get you Eashan Morajkar
8th Jun 2021, 6:08 AM
Atul [Inactive]
+ 2
For input 1:00 AM It shud output 01:00 But in your code it will be 1:00 Just append 0 before for these kind of cases:)
8th Jun 2021, 6:14 AM
Nivya
Nivya - avatar
+ 2
Nivya Can you post your Sol so that I can find alternatives for my Sol?
8th Jun 2021, 7:55 AM
Atul [Inactive]
+ 1
Nivya for 2:00 AM. It should print 02:00 ?
8th Jun 2021, 6:37 AM
Atul [Inactive]
0
Yes... check that output format in description XX:XX it's like this right so our output should be appended with 0 if it's 1 number do like this if it's AM and length is less then 2 just append tht number with 0 if(AM){ if((length before ":") !=2){ append 0 }} something like this
8th Jun 2021, 7:02 AM
Nivya
Nivya - avatar
0
No other option! we left with, its a format to show time in xx:xx this format ^^
8th Jun 2021, 7:30 AM
Nivya
Nivya - avatar
0
Atul It seems working now. -------- There is another solution with SimpleDateFormat import java.util.*; import java.text.SimpleDateFormat; import java.text.DateFormat; import java.util.Date; import java.text.ParseException; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String input = sc.nextLine(); DateFormat df = new SimpleDateFormat("hh:mm aa"); DateFormat outputformat = new SimpleDateFormat("HH:mm"); Date date = null; String output = null; try { date = df.parse(input); output = outputformat.format(date); System.out.println(output); } catch(ParseException pe) { pe.printStackTrace(); } } }
8th Jun 2021, 8:47 AM
A͢J
A͢J - avatar
- 2
Well it did not use to work but now somehow it worked
8th Jun 2021, 6:03 AM
Eashan Morajkar
Eashan Morajkar - avatar
- 2
I get the answer correct
8th Jun 2021, 6:10 AM
Eashan Morajkar
Eashan Morajkar - avatar
- 2
Sure Atul here u go=> //Code import java.util.*; public class Program { public static void main(String[] args) { Scanner s=new Scanner(System.in); String str=s.nextLine(); String []in=str.split(":"); String []in1=in[1].split(" "); String day="AM"; String nyt="PM"; String d= str.substring(str.length()-2,str.length()); if(d.equals(day)){ if(in[0].length()!=2) { System.out.print("0"+str.substring(0,str.length()-3)); } else System.out.print(str.substring(0,str.length()-3)); } if(d.equals(nyt)){ int i=Integer.parseInt(in[0])+12; String res=Integer.toString(i)+":"+in1[0]; System.out.print(res); } } }
8th Jun 2021, 8:58 AM
Nivya
Nivya - avatar