on 08-03-2006 7:51 AM
Hi
I want to code a function which comapres an array that contains "X" or empty values,with an array which contains only "X" and return a boolean array with boolean arguments (true/false)
any ideas?
Thx,Shai
Hi Shai,
This is the code that you had asked for . This method returns an array of booleans .
public boolean[] comparison()
{
String[] firstArray = {"X","X",""};
String[] secondArray = {"X","X","X"};
int lengthOfFirstArray = firstArray .length;
int lengthOfSecondArray = secondArray.length;
int lengthOfResultantArray = Math.max(lengthOfFirstArray,lengthOfSecondArray);
boolean[] resultantArray = new boolean[lengthOfResultantArray];
for (int countCharacter=0;countCharacter<firstArray.length;countCharacter++ )
{
if(firstArray[countCharacter].equals(secondArray[countCharacter]))
{
resultantArray[countCharacter] = true;
}
else{
resultantArray[countCharacter] = false;
}
}
return resultantArray;
}
Regards,
Tahzeeb
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shai,
Following code will help you,
String arr_1[] = {"X", "", "X", ""};
String arr_2[] = {"X", "X", "X", "X"};
boolean arr_3[] = new boolean[arr_1.length];
foo(arr_1, arr_2, arr_3);
where the function could be like,
void foo(String[ ] arr_1, String[ ] arr_2, boolean[ ] arr_3 ) {
for(int i=0; i<arr_1.length; i++) {
if( arr_1[ i ] != null && arr_2[ i ].equalsIgnoreCase (arr_1[ i ]) ) {
arr_3[ i ] = true;
} else {
arr_3[ i ] = false;
}
}
}
I hope this will help you.
Regards,
Guru.
PS: Award points for helpfull replies.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.