/**
*This program converts the time into words.
* @author : Nitendra Kumar
*/
import java.util.Scanner;
class timetonum
{
public void display_time()
{
Scanner in=new Scanner(System.in);
System.out.println("Enter hours...(1-12)");
int hh=in.nextInt();
System.out.println("Enter minutes...(0-59)");
int mm=in.nextInt();
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("Invalid time");
else if(mm==0)
System.out.println(time[hh-1] + " o'clock");
else if(mm==30)
System.out.println("Half past " +time[hh-1]);
else if(mm==15)
System.out.println("Quarter past " +time[hh-1]);
else if(mm==45)
System.out.println("Quarter to " +time[hh]);
else if(mm<30 && mm!=15)
System.out.println(time[mm-1] +" minutes past " +time[hh-1]);
else if(mm>30 && mm!=45)
System.out.println(time[60-mm-1] + " minutes to " +time[hh]);
}
public static void main()
{
timetonum ob=new timetonum();
ob.display_time();
}
}
OUTPUT:
Enter hours...(1-12)
5
Enter minutes...(0-59)
10
Ten minutes past Five
/*---------------Program developed by: Nitendra Kumar---------------*/
//For more details visit http://javawithnitendra.blogspot.in
No comments:
Post a Comment
Ur comments r most welcome...