DEV Community

loading...

Discussion on: Daily Challenge #48 - Facebook Likes

Collapse
vivek97 profile image
Vivek97
    public String message(List <String> list)
    { 
        switch(list.toArray().length){
        case 0:
            return "no one likes this";
        case 1: 
             return list.get(0)+" likes this";
        case 2: 
             return list.get(0)+" and "+list.get(1)+" like this";
        case 3: 
             return list.get(0)+", "+list.get(1)+" and "+list.get(2)+" like this";
        default: 
             return list.get(0)+","+list.get(1)+" and "+(list.toArray().length-2)+" other like this";   
        }


`