我正在制作一个偶数游戏,我使用下面的代码,似乎有些错误,有人可以帮我检查一下吗? [英] I am making an even number game, I used the following code, something seems to be wrong, can anyone help me check it please?
本文介绍了我正在制作一个偶数游戏,我使用下面的代码,似乎有些错误,有人可以帮我检查一下吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
这篇关于我正在制作一个偶数游戏,我使用下面的代码,似乎有些错误,有人可以帮我检查一下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文