我正在制作一个偶数游戏,我使用下面的代码,似乎有些错误,有人可以帮我检查一下吗?
问题描述:
static bool EvenNumber(int num)
{
bool value = true;
int multiple = num / 2;
int i = 0;
for(i = 0; i< = 100; i ++)
{
if ((num%2)== 1)
value = false;
}
返回值;
}
static bool EvenNumber (int num)
{
bool value = true;
int multiple = num / 2;
int i = 0;
for (i = 0; i <= 100; i++)
{
if ((num % 2) == 1)
value = false;
}
return value;
}
答
你了解代码吗?你从哪里得到代码?
为什么有一个从未使用的倍数和for循环的用途?
试试这个例子:
Do you understand the code? where did you get the code from?
Why is there a multiple that was never used and what is the use of the for loop?
Try this example:
static bool EvenNumber (int num)
{
bool isEven = true;
if (Math.Abs(num % 2) == 1)
isEven= false;
return isEven;
}
检查数字是否均匀使用这个简单的代码:
static bool EvenNumber(int num)
{
if(num%2 == 0)
返回true
else
返回false
}
to check a num is even or not use this simple code :
static bool EvenNumber (int num)
{
if(num%2==0)
return true
else
return false
}
你可以使用单行检查int偶数或奇数值
You can use single line to check int value for even or odd
public static bool IsEven(int num)
{
return num%2 == 0;
}
public static bool IsOdd(int num)
{
return num%2 != 0;
}