题目
哦不,蒂米创造了一个无限循环!帮助Timmy找到并修复他未完成的For循环中的错误!
import java.util.*;
class Kata {
public static List CreateList(int number)
{
List list = new ArrayList();
for(int count = 1; count <= number;)
{
list.add(count);
}
return list;
}
}
测试用例
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
import java.util.*;
public class SolutionTest {
Kata k = new Kata();
@Test
public void SampleTests() {
assertEquals(Arrays.asList(1), k.CreateList(1));
assertEquals(Arrays.asList(1,2), k.CreateList(2));
assertEquals(Arrays.asList(1,2,3), k.CreateList(3));
assertEquals(Arrays.asList(1,2,3,4), k.CreateList(4));
assertEquals(Arrays.asList(1,2,3,4,5), k.CreateList(5));
}
}
解题
My
import java.util.*;
class Kata {
public static List CreateList(int number)
{
List list = new ArrayList();
for(int count = 1; count <= number;count++)
{
list.add(count);
}
return list;
}
}
后记
题目似乎过于简单了。