【发布时间】:2014-12-02 13:59:24
【问题描述】:
我正在尝试编写从颜色 rgb 转换为 hsv 的代码,但编译器似乎看不到 if 条件中的内容 这是代码 包问题2;
public class HSVRGB {
double d;
double e;
double g;
//Java program that takes an input a color code in HSV and
输出等效的 RGB 代码,反之亦然。
public static void convert(double d,double e,double g){ /// my hsv inputs that am gonna check
double t;
double p ;
double q;
double f;
double Hi;
//my other variable am gonna use to produce the output
Hi=(d/60);
f=(d/60)-Hi;// here's the formula that will proceed the code
if(Hi==0) {
t=g*(1-(1-f)*e);
p=g*(1-e);
System.out.print("R="+ g + "G=" + t + "b=" + p );
// the given input should pass into the above if condition since its true
}
else
if(Hi==1){
q=g*(1-f*e);
p=1-e;
System.out.print("R="+q+"G="+g+"b="+p);
}
else
if(Hi==2){
p=g*(1-e);
t=g*(1-(1-f)*e);
System.out.print("R="+p + "G="+ g + "B="+t);
}
else
if(Hi==3){
p=g*(1-e);
q=g*(1-(f*e));
System.out.print("R="+p + "G="+q + "B=" + g );
}
else
if(Hi==4){
t=g*(1-(1-f)*e);
p=g*(1-e);
System.out.print("R"+t+"G"+p+"B"+g);
}
else
if(Hi==5){
p=g*(1-e);
q=g*(1-(f*e));
System.out.print("R="+g+ " G"+p+"B="+q );
}
else
System.out.print("Invalid Inpjdsnabfvkdbfjsv,hdbut"); //it only print this message
}
public static void main (String[]args){
convert(100.34,0.74,0.78);
}
}
【问题讨论】:
-
为什么不将
Color.getHSBColor()与 RGB 组件一起使用?
标签: java if-statement nested conditional-statements