I have two array. They are represent x-coordinates and y-coordinates. The code is like that if both coordinates are same it print a statement "Both co ordinates are same" else they print They are not same.
My code is
public class Arraypairmatching {
public static void main(String args[]){
double[]xcoordinate={2.3,1.2,3.3,5.5,2.3,1.3,7.9,1.2,3.3,3.3,5.2};
double[]ycordinate={5.4,2.2,4.4,6.6,5.4,1.9,5.2,2.2,3.5,4.4,4.2};
int i=0,k=0;
while(i<xcoordinate.length){
if(xcoordinate[i]&&ycordinate[i]==xcoordinate[k]&&ycordinate[k]){
System.out.println("Both co ordinates are same");
i++;
k=i+1;
}
else{
System.out.println("They are not same");
}
}
}
}
If I analysis the array I can see that 2.3 and 5.4 are pair,1.2 and 2.2 are pair and so on. As you can see 2.3 and 5.4 is repeat at 5th pair. So in this time they print They are same.
But the code block not run for that if statement.
Error: Error:(9, 30) java: bad operand types for binary operator '&&' first type: double second type: boolean
How could this pairwise matching possible in java?
Aucun commentaire:
Enregistrer un commentaire