import java.io.*;
class TimeInWords
{
public void display_time()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter hours.....(1-12)");
int hh=Integer.parseInt(br.readLine());
System.out.println("Enter minutes.....(0-59)");
int mm=Integer.parseInt(br.readLine());
String time[]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine",
"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen",
"Eighteen","Nineteen","Twenty","Twenty One","Twenty Two","Twenty Three",
"Twenty Four","Twenty Five","Twenty Six","Twenty Seven","Twenty Eight",
"Twenty Nine"};
if(hh>12 || mm>60)
System.out.println("The Time is invalid");
else if(mm==0)
System.out.println("The time is "+time[hh-1]+" o'Clock");
else if(mm<30 && mm!=15)
System.out.println("The time is "+time[mm-1]+" minute(s) past "+time[hh-1]);
else if(mm==15)
System.out.println("The time is quarter past "+time[hh-1]);
else if(mm==30)
System.out.println("The time is "+time[hh-1] + " Thirty");
else if(mm==45 && hh!=12)
System.out.println("The time is quarter to "+time[hh]);
else if(mm==45 && hh==12)
System.out.println("The time is quarter to "+time[0]);
else if(mm>30 && hh!=12)
System.out.println("The time is "+time[60-mm-1]+" minute(s) to "+time[hh]);
else if(hh==12 && mm>30)
System.out.println("The time is "+time[60-mm-1]+" minute(s) to "+time[0]);
}
}
3 comments:
Thanks ...helped me in my comp practicals :)
can anyone please explain the if else if loops mentioned here ?
Use http://hilite.me/
for better visibility of code
Post a Comment