数组a包含数字的数字。在这个例子中,我将插入随机数字,但代码必须适用于任何数字集合。我必须将数组中的整数相加,然后将该总和中的最后一位数字存储到称为校验和的变量中。简单校验和算法
在这个例子中,3 + 5 + 7 = 15所以校验和会= 5.这是我的代码到目前为止。我将如何去计算校验和?
int[] a = { 3, 5, 7 };
int checksum = 0;
int i = 0;
while (i < a.length)
{
checksum += a[i];
i++;
}
checksum = ???????;
你在找? http://stackoverflow.com/questions/2609315/recognizing-when-to-use-the-mod-operator – irrelephant