本文介绍了如何将for循环转换为while循环来计算相当于华氏温度java的摄氏温度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打印出两张计算相当于华氏温度的摄氏温度的表格。我有一个for循环表,但是当我尝试为我的代码添加while循环时,它只打印出一个表而不是两个表。我做错了什么?



我尝试过:



这是我的代码:

I trying to print out two tables that that calculates the Celsius equivalent to Fahrenheit Temperatures. I have one table for loop, but when I try to put while loop for my code it just print out one table not two table. What I am doing wrong?

What I have tried:

here is my code:

public class TempLoops {
	
	public static void main(String args[]) {
		int fahrenheit = 0;
		
        System.out.println("Fahrenheit    Celsius");
		
        for ( fahrenheit = 0; fahrenheit <= 300; fahrenheit+= 20) {    
            
			System.out.printf("%5d        ",fahrenheit);
            double Celsius = (fahrenheit-32.0) * (5.0/9.0);  // formula for celsius to fahrenheit conversion
			
            System.out.printf("%1.1f", Celsius );
            System.out.println();
		}		
		while ( fahrenheit <= 300) {   
		  fahrenheit+= 20;
            System.out.println("Fahrenheit    Celsius");
			System.out.printf("%5d        ",fahrenheit);
            double Celsius = (fahrenheit-32.0) * (5.0/9.0);  // formula for celsius to fahrenheit conversion
			
            System.out.printf("%1.1f", Celsius );
            System.out.println();
		}
	}
}

推荐答案

fahrenheit = 0;
while(fahrenheiht <= 300)
{



这篇关于如何将for循环转换为while循环来计算相当于华氏温度java的摄氏温度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 09:29