使用do-while实现:输出摄氏温度和华氏温度的对照表,要求它从摄氏温度0度到250度,每隔20度为一项,对照表的条目不超过10条,
转换关系:华氏温度=摄氏温度*9/5.0+32
提示:
1。循环操作:计算摄氏温度并输出对照条目
2,循环条件:条目<=10&&摄氏温度<=250不知道那个条目<=10该怎么设置循环条件`
下面是我的代码`public class Demo01 { public static void main(String[] args) 
{

int sheC=0;
double huaC=0;
do {
huaC=sheC*9/5.0+32;
System.out.println("摄温度为"+sheC+"时,摄氏温度为"+huaC);
sheC=sheC+20;


} while (sheC<=250);


}
}

解决方案 »

  1.   

    加个计数器啊public class Demo01 {public static void main(String[] args)
    {int sheC=0;
    double huaC=0;
    int count=0;
    do {
    huaC=sheC*9/5.0+32;
    System.out.println("摄温度为"+sheC+"时,摄氏温度为"+huaC);
    sheC=sheC+20;
    count++;} while ((count<=10) &&(sheC <=250));
    }
    }
      

  2.   

    从摄氏温度0度到250度,每隔20度为一项,对照表的条目不超过10条
    代码应该如下:class Test6 {  public static void main(String[] args) 
    {  int sheC=0; 
    double huaC=0;
    int i=0;
    int count=1;
    do {

    i++;            /////

    huaC=sheC*9/5.0+32; 
    System.out.println("摄温度为"+sheC+"时,摄氏温度为"+huaC); 
    sheC=sheC+1;
    if(i==20){
    count++;
    System.out.println("*********************");
    i=0;
    }
    } while (sheC <=250 && count<=10); 


     
     
     
      

  3.   

    楼上的,你的意思是以20度为一个大项,里面每度你也做了一个转换·
    而题目意思是以20度作为一个分割点,并不需要每度都做·,所以sheC=sheC+1;  这些是多余的