You are viewing a single comment's thread. Return to all comments →
public static String timeInWords(int h, int m) { // Write your code here String[] num = { "half", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty" };
String time; if (m == 0) { time = num[h] + " o' clock"; } else if (m == 15) { time = num[m] + " past " + num[h]; } else if (m == 30) { time = num[0] + " past " + num[h]; } else if (m == 45) { time = num[15] + " to " + num[h+1]; } else if (m == 1) { time = num[1] + " minute past " + num[h]; } else if (m <= 20) { time = num[m] + " minutes past " + num[h]; } else if (m < 30) { time = num[20] + " " + num[m-20] + " minutes past " + num[h]; } else if (m < 40) { time = num[20] + " " + num[40-m] + " minutes to " + num[h+1]; } else { time = num[60-m] + " minutes to " + num[h+1]; } return time; }
}
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
public static String timeInWords(int h, int m) { // Write your code here String[] num = { "half", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty" };
}