Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在android中比较int[]数组和int?_Java_Android_Arrays - Fatal编程技术网

Java 如何在android中比较int[]数组和int?

Java 如何在android中比较int[]数组和int?,java,android,arrays,Java,Android,Arrays,我需要比较int[]数组和整数值。这是我的密码 int c1[], c2[], c3[]; int count1=0, count2=1, count3=0; c1 = new int[] { count1 }; c2 = new int[] { count2 }; c3 = new int[] { count3 }; 现在我需要将这个int[]数组与int进行比较,也就是说,任何数组都等于0,那么代码就不需要执行。如果不等于0,那么代码就执行。如何比较??先帮我谢谢好吗?如果我尝试了这个条件

我需要比较int[]数组和整数值。这是我的密码

int c1[], c2[], c3[];
int count1=0, count2=1, count3=0;
c1 = new int[] { count1 };
c2 = new int[] { count2 };
c3 = new int[] { count3 };
现在我需要将这个int[]数组与int进行比较,也就是说,任何数组都等于0,那么代码就不需要执行。如果不等于0,那么代码就执行。如何比较??先帮我谢谢好吗?如果我尝试了这个条件,但它不会完全执行

if(c1.equals(0))
{
 // skip
}
else 
{
 // execute code
}

上述代码无效。

也许您正在寻找:

if(c1[0] == 0)
{
 // skip
}
else 
{
 // execute code
}

虽然还不清楚如果c1只包含一个整数,为什么需要将其作为数组。

也许您正在寻找:

if(c1[0] == 0)
{
 // skip
}
else 
{
 // execute code
}
尽管还不清楚,如果c1只包含一个整数,为什么需要将其作为数组。

使用c1[0],c1[1]。。。。and(循环迭代)

像-

使用c1[0],c1[1]。。。。and(循环迭代)

像-

请尝试以下操作:

for(int i=0;i<cl.length;i++){
   if(c1[i]==0)
    {
     // skip
    }
   else 
   {
 // execute code
   }
}
对于(int i=0;i请尝试以下操作:

for(int i=0;i<cl.length;i++){
   if(c1[i]==0)
    {
     // skip
    }
   else 
   {
 // execute code
   }
}

for(int i=0;ii认为这个问题非常相似[在此处输入链接描述][1][1]:我认为这个问题非常相似[在此处输入链接描述][1][1]: