Wednesday, December 1, 2010

Prog for convert time in word format in java

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:

Anonymous said...

Thanks ...helped me in my comp practicals :)

Anonymous said...

can anyone please explain the if else if loops mentioned here ?

Amogh Antarkar said...

Use http://hilite.me/

for better visibility of code