天天看点

9. 使用do-while实现:输出摄氏温度与华氏温度的对照表,要求它从摄氏温度0度到250度,每隔20度为一项,对照表中的条目不超过10条。 转换关系:华氏温度 = 摄氏温度 * 9 / 5.0 +

public class Ex09 {

    public static void main(String[] args) {

        // TODO Auto-generated method stub

double c=0;//摄氏度初始值为0

int i=0;//条目数初始值为0

double f=0;//华摄氏度

do {

    i++;

    f=c* 9 / 5.0 + 32;//

    //每20度为一项

    c+=20;

    System.out.println("摄氏度为"+c+"华摄氏度为"+f);

}

while(i<=10&&c<=250);//运行条件为条目数不超过10以及温度不超过250

    }

}