posted 24 years ago
Why are you doing all that math? Putting the results of the calculations in a static array would make it much faster/easier to read. Pseudocode follows.
public class CCThingy
{
public static int[] results = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
public boolean checkIt(int ccarray[])
{
// Sanity checking removed, you can figure
// that out for yourselves.
boolean flip = false;
int sum = 0;
for(int i = ccarray.length; i >= 0; i--)
{
if(flip)
{
sum += results[ccarray[i]];
} else {
sum += ccarray.length[i];
}
}
return (sum % 10 == 0);
}
This way you don't have to calculate values that aren't going to ever change. And you don't have to multiply something by 1.
------------------
--I'm Hugh Jass.