We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My java solution. Not all tests pass and i don't understand why. If i test them by hand they pass, but sending solution makes them not pass (for example test 2)
class Result {
/*
* Complete the 'timeInWords' function below.
*
* The function is expected to return a STRING.
* The function accepts following parameters:
* 1. INTEGER h
* 2. INTEGER m
*/
private static final String[] NUMBERS = {
"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen",
"eighteen", "nineteen", "twenty", "twenty one", "twenty two", "twenty three",
"twenty four", "twenty five", "twenty six", "twenty seven", "twenty eight",
"twenty nine", "half"
};
public static String timeInWords(int h, int m) {
// Write your code here
StringBuilder b = new StringBuilder();
if(m > 0 && m <= 30) {
System.out.print(NUMBERS[m] + " past " + NUMBERS[h]);
b.append(NUMBERS[m] + " past " + NUMBERS[h]);
} else if(m > 30) {
System.out.print(NUMBERS[60-m] + " minutes to " + NUMBERS[h+1]);
b.append(NUMBERS[60-m] + " minutes to " + NUMBERS[h+1]);
} else {
System.out.print(NUMBERS[h] + " o' clock");
b.append(NUMBERS[h] + " o' clock");
}
return b.toString();
}
}
Not all
Cookie support is required to access HackerRank
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 →
My java solution. Not all tests pass and i don't understand why. If i test them by hand they pass, but sending solution makes them not pass (for example test 2)
class Result {
}
Not all