寻找某两个数相除,其结果 离黄金分割点 0.618最近
分母和分子不能同时为偶数
分母和分子 取值范围在[1-20]
public class HelloWorld {
public static void main(String[] args){
float y=0.618f;
float x=0;
float z=0;
int a=0;
int b=0;
for (int i=1;i<=20;i++){
for (int j=20;j>=1;j--){
if (0==i%2 & 0==j%2)
continue;
z = (float) i/j;
if (Math.abs(x-y)>Math.abs(z-y)){
x = z;
a=i;
b=j;
}
}
}
System.out.println("离黄金分割点最近的两个数相除是"+a+"/"+b+"="+x);
}
}