• + 0 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 {

    /*
     * 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