我是编程新手。请帮我解决这个错误。
static int cif2(int a)
{
do
{
if (a % 10) s++;
a = a / 10;
} while (a > 0);
return s;
}
static void Main(string[] args)
{
do
{
ok = true;
for (int i = 0; i < n - 1; i++)
if (cif2(v[i]) >cif2(v[i + 1]))
{
int t = v[i];
v[i] = v[i + 1];
v[i + 1] = t;
ok = false;
}
} while (!ok);
错误指向if(a%10)但我在这里看不到问题..
答案 0 :(得分:0)
您应该拥有以下cif2
方法。
static int cif2(int a)
{
var s = 0;
do
{
if (a % 10 != 0) //I am not sure of your requirement. The other option would be if(a % 10 == 0)
{
s++;
}
a = a / 10;
} while (a > 0);
return s;
}