Comparing Arrays
in
Programming Questions
•
2 years ago
I've got a bit of code that takes compares entries in an array, but it's a hell of a mess and I'm sure there's a smarter way of doing it, I was wondering if anyone could point me in the right direction.
I've got an array of tab separated information in the format:
where each of the vars is a number between 1 and 7. What I want to do is compare each of the array entries, but only in the 'column' in which it's in, and where there's a match, work out the percentage correlation between the entries.
My current code relies on a set of nested for loops:
Thanks!
I've got an array of tab separated information in the format:
- "name '\t' var1 '\t' var2 '\t' var3 '\t' var4 '\t' var5 '\t' var6 '\t' var7"
where each of the vars is a number between 1 and 7. What I want to do is compare each of the array entries, but only in the 'column' in which it's in, and where there's a match, work out the percentage correlation between the entries.
My current code relies on a set of nested for loops:
- public void crunchData() {
- for( int i = 0; i < allData.length; i++){
- String[] current = split(allData[i], '\t');
- for( int j = 0 ; j < allData.length; j++){
- int counter = 0;
- String[] compare = split(allData[j], '\t');
- if ( current[0].equals(compare[0]) == false){
- for( int k=0; k < current.length ; k ++){
- if(compare[k].equals(current[k]) == false) {
- counter++;
- }
- }
- }
- if (counter>0){
- float percentage = (counter/(current.length-1)) * 100;
- }
- }
- }
- }
Thanks!
1