forked from IF-LK-2020/array
xor() finished
This commit is contained in:
12
Arrays.java
12
Arrays.java
@@ -217,6 +217,18 @@ public class Arrays {
|
||||
* Für ein leeres Array wird <code>false<code> zurück gegeben.
|
||||
*/
|
||||
public boolean xor( boolean[] pArray ) {
|
||||
if( pArray.length == 0 ) {
|
||||
return false;
|
||||
}
|
||||
int sum =0;
|
||||
for(int i=0;i<pArray.length;i++){
|
||||
if(pArray[i]== true){
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
if(sum != 1){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user