Try with
for(int k=0;k<5;k++)
{
n=Math.abs(n2[k]-n1[k]);
m= 10- n;
if(n<=m)
sum=sum+n;
else
sum=sum+m;
n=0;m=0;
}
Quote:
This works too,but I cannot understand where is my code going wrong. Thanks for the help.
Your code is going wrong because m is wrong.
Since a wheel is 10 positions, and
n
is the number of clicks one way, the other way is
10-n
and your
m
is not doing that because
n2[k]-n1[k]
is positive or negative.
Quote:
My n2[k]-n1[k] is always positive as I have used Math.abs and if you check the formula,it perfectly fits.
n2[k]-n1[k]
is positive because embedded in
abs()
, look at
m
, it is embedded in
abs()
with something else, the problem is the something else that is in the
abs()
.
Said otherwize,
m=10-Math.abs(n2[k]-n1[k]);
m=Math.abs((9-n2[k])+(n1[k]+1));
m=Math.abs(10-(n2[k]-n1[k]));
are 2 different things