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 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=1;
while(i<xcoordinate.length){
//if(xcoordinate[i]&&ycordinate[i]==xcoordinate[k]&&ycordinate[k]){
if(xcoordinate[i]==xcoordinate[k]&&ycordinate[i]==ycordinate[k]){
System.out.println("Both co ordinates are same");
i++;
if(k<xcoordinate.length) {
k = i + 1;
}
}
else{
System.out.println("They are not same");
}
k++;
}
}
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: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11
How to eliminate this error and also how to store the They are not same types of data?
Like want to store{ {1.2,3.3,5.5}and{2.2,4.4,6.6} }and {{3.3,5.5,2.3,1.3,7.9}and{4.4,6.6,5.4,1.9,5.2}} ..... separately.
See Question&Answers more detail:
os