帮我用JAVA,(do while)结构算出这道题,然后再详细解释下,谢谢!

2025-03-26 00:56:39
推荐回答(4个)
回答1:

/**

 * 

class:比较摄氏华氏



 * */

public class TempCont {

 public static void main(String args[]){

  //声明化摄氏度华氏度对象

  float celsius = 0;

  float Fahrenheit = 0;

  int i = 0;

  //比较次数不超过10次

  System.out.println("对照表关系如下:");

  do{

   celsius += 20;

   Fahrenheit = (celsius*9)/5+32;

   System.out.println("摄氏度:"+celsius+"\t华摄氏度:"+Fahrenheit);

   i++;

  }while(celsius<250&&i<10);

   

  

 }

}

回答2:

public class Test {
    
    /**
     * 打印摄氏与华氏温度对应关系 
     * @data 2013-9-27
     */
    public void print(){
        System.out.print("摄氏温度      ");
        System.out.println("华氏温度");
        int ss = 0 ;//初始化摄氏温度
        int hs;//对应的华氏温度
        int j = 0;//输出条目控制
        //开始循环输出
        do{
            hs = ss*9/5+32;
            System.out.print(ss+"   ");
            System.out.println(hs);
            ss = ss + 20;//进入下一个温度迭代
            j++;
        }while(ss<=250 && j<=10);//结束条件 摄氏温度大于250且输出条目大于10
    }
    
    public static void main(String args[]) {
        //运行打印
        new Test().print();
    }
}

很简单的 有什么不懂请继续提问

回答3:

public class TestDoWhile {
public static void main(String[] args) {
int c = 0;//摄氏度,从0开始
int t = 0;//条数,从0开始
do {
System.out.println("摄氏度:" + c + " 华氏度:" + (c*9/5 + 32));
c = c + 20; //按20递增
t++; //按1递增
}
while(c <= 250 && t <= 9);
}
}

回答4:

这个是先计算后判断,自己思考