I am trying to create a HashMap
for a Farey sequence of degree 6 where the denominator is the key and the fraction is the value. My code is:
public class FareySequence {
public static void main(String[] args){
Map<Double, Double> map = new HashMap<Double, Double>();
for(double n = 1.0; n < 6.0; n++){
for(double d = 6.0; d > n; d--){
double frac = n / d;
if(frac < 1){
if(!map.containsValue(frac)){
map.put(d, frac);
}
}
}
}
System.out.print(map);
}
}
However, when I run it, I get:
{
4.0=0.75,
2.0=0.5,
5.0=0.8,
6.0=0.8333333333333334,
3.0=0.6666666666666666
}
What am I doing wrong?