天天看點

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

    }

}