(Celsius to Fahrenheit conversion) Write a program that displays a table of temperatures from 0C to 20C and their Fahrenheit equivalents. The formula for converting from the Celsius scale to the Fahrenheit scale is
F= (9/5) C + 32
where F is the temperature in Fahrenheit and C is the temperature in Celsius.
CelsiustoFahrenheit.java
/**
* Celsius to Fahrenheit conversion.
*/
import javax.swing.JOptionPane; // import JOptionPane.
public class CelsiustoFahrenheit {
public static void main(String[] args) {
float fahrenheit,celcius;
String result = "";
for(celcius=0;celcius<=20;celcius++){
fahrenheit = (celcius*9/5)+32; // Convert formula.
result += celcius +" Celcius = " + fahrenheit +" Fahrenheit \n";
} // End of for loop.
// Print table.
JOptionPane.showMessageDialog(null,result,"The Table Of Celcius to Fahrenheit Conversion",JOptionPane.INFORMATION_MESSAGE);
} // End of main method.
} // End of class.
Yorum Yok:
Yorum Yap:
Yorum yapabilmek için giriş yapmalısınız.



