java - Returning a remainder -


@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; 

so whenever run test supposed return number make individual numbers added in zipcode clean division of 10, when supposed return 9 returns 1 instead. going wrong code?


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -