double[] intervalPoint = {0, 0.2, 0.1, 0.3, 0.2, 0.3};
int intervalNum = intervalPoint.length/2;
Interval1D[] intervals = new Interval1D[intervalNum];
for(int i=0; i<intervals.length; i++){
intervals[i] = new Interval1D(intervalPoint[2*i], intervalPoint[2*i+1]);
}
for(int i=0; i<intervals.length; i++){
for(int j=i+1; j<intervals.length; j++){
if(isIntersection(intervals[0], intervals[j]))
System.out.println("(" + intervals[i] + ", " + intervals[j] + ")");
}
}
/**
* 判断区间a,b是否有交集
* @param a
* @param b
* @return
*/
public static boolean isIntersection(Interval1D a, Interval1D b){
if(a.contains(b.min()) || a.contains(b.max()))return true;
if(b.contains(a.min()) || b.contains(a.max()))return true;
return false;
}