2014-12-26 40 views
0

我需要比較int []數組與整數值。這段代碼時遇到如何在android中比較int []數組與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 []數組與詮釋比較,這是任何數組等於0,則代碼不需要執行如果不等於則代碼執行。如何比較?提前幫助我感謝?這如果條件我試過,但它不會完全執行。

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

上述代碼無法正常工作。

+0

我認爲這個問題非常相似[1] [1]:http:// stackoverfl ow.com/questions/9710947/android-compare-arrays – najmulhasan

回答

3

嘗試以下:

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

也許你正在尋找:

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

雖然目前還不清楚爲什麼你需要C1是一個數組,如果它僅持有一個整數。

1

使用C1 [0],C [1] ...和(通過環迭代)

喜歡 -

if(c1[0]==0)