codewars059 - Create Phone Number

Instructions

Linkjava

Solution:

public class Kata{
    public static String createPhoneNumber(int[] numbers){
            return String.format("(%d%d%d) %d%d%d-%d%d%d%d", numbers[0],numbers[1],numbers[2],numbers[3],numbers[4],numbers[5],numbers[6],numbers[7],numbers[8],numbers[9]);

    }    
}

Sample Tests:

import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class PhoneExampleTests{
    @Test
    public void tests(){
        assertEquals("(123) 456-7890", Kata.createPhoneNumber(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}));
    }    
}
相關文章
相關標籤/搜索