We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticStringtimeInWords(inth,intm){// Write your code hereStringtime[]={" o' clock","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","quarter","sixteen","seventeen","eighteen","nineteen","twenty","twenty one","twenty two","twenty three","twenty four","twenty five","twenty six","twenty seven","twenty eight","twenty nine","half"};StringtimeInWord="";if(m==0){timeInWord=time[h]+time[0];}elseif(m==30||m%30==15){timeInWord=(m>30)?time[60-m]:time[m];timeInWord+=(m>30)?" to ":" past ";timeInWord+=(m>30)?time[h+1]:time[h];}else{timeInWord=(m>30)?time[60-m]:time[m];timeInWord+=(m==1)?" minute":" minutes";timeInWord+=(m>30)?" to ":" past ";timeInWord+=(m>30)?time[h+1]:time[h];}returntimeInWord;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Time in Words
You are viewing a single comment's thread. Return to all comments →
Java