本文介绍了如何检查多个变量是否等于相同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较多个项目?例如,我想检查所有变量A,B和C是否等于char'X',或者所有三个都等于'O'。 (如果其中2个是X,一个是O,它应该返回false。)
我试过:
if(A,B,C =='X'|| A,B,C =='O')
{
// Do whatever
}
但它不工作。
$ if((A ==' X'|| A =='O')&& A == B& B == C)
{
// Do whatever
}
How do I compare multiple items? For example, I wish to check if all the variables A, B, and C are equal to the char 'X' or all three are equal to 'O'. (If 2 of them are X and one is O it should return false.)
I tried:
if (A, B, C == 'X' || A, B, C == 'O')
{
//Do whatever
}
but it didn't work. What is the best way to do this?
解决方案
if((A == 'X' || A == 'O') && A == B && B == C)
{
// Do whatever
}
这篇关于如何检查多个变量是否等于相同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!