-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.java
42 lines (42 loc) · 1.42 KB
/
clock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Q10
import java.util.*;
public class clock
{
void main(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter time");
int h = sc.nextInt();
int m = sc.nextInt();
String a[]= {"one","two","three","four","five","six","seven","eight","nine","ten",
"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen","twenty"};
String b[]={"twenty","thirty","fourty","fifty"};
if(h>0 && h<=12 && m>=0 && m<=60){
System.out.print(h);
if(m<10)
System.out.print(":0"+m+"\t");
else
System.out.print(":"+m+"\t");
if(h==12)
h=0;
if(m==0)
System.out.print(a[h-1]+" O' clock");
else if(m==15)
System.out.print("quarter past "+a[h-1]);
else if(m<=20)
System.out.print(a[m-1]+" minutes past "+a[h-1]);
else if(m<30)
System.out.print("twenty "+a[m-21]+" minutes past "+a[h-1]);
else if(m==30)
System.out.print("half past "+a[h-1]);
else if (m==45)
System.out.println("quarter to "+a[h]);
else if(m<=40)
System.out.print("twenty "+a[39-m]+" minutes to "+a[h]);
else
System.out.print(a[59-m]+" minutes to "+a[h]);
}
else
System.out.println("incorrect input");
}
}