返回剩余部分

时间:2016-04-21 21:32:53

标签: java

@Test
public void testCheckDigit()
{
    ZipCode z7 = new ZipCode (12345);
    assertEquals(5, z7.getCheckDigit());
    ZipCode z8 = new ZipCode (01234);
    assertEquals(0, z8.getCheckDigit());
    ZipCode z9 = new ZipCode (11234);
    assertEquals(9, z9.getCheckDigit());
    ZipCode z10 = new ZipCode (10044);
    assertEquals(1, z10.getCheckDigit());
}
public int getCheckDigit()
{

while(zipCode > 0)
{
    digitCheck = digitCheck + zipCode % 10;
    zipCode = zipCode / 10;
    digitCheck = digitCheck % 10;

}

return digitCheck;

所以每当我运行测试时,它应该返回一个数字,这个数字会使ZipCode中的各个数字全部加起来为10,但是当它应该返回9时,它会返回1。我的代码出了什么问题?

0 个答案:

没有答案