Difference between revisions of "Temperature Calculator"
From CompSciWiki
Line 9: | Line 9: | ||
<br/> | <br/> | ||
Example: User inputs "c" and "10" would result in "50f" | Example: User inputs "c" and "10" would result in "50f" | ||
− | |||
<br/> | <br/> | ||
Line 61: | Line 60: | ||
<pre> import javax.swing.*;</pre> | <pre> import javax.swing.*;</pre> | ||
− | + | <br/> | |
Define your variables, we will need doubles in case of decimal results, and a string value for the unit | Define your variables, we will need doubles in case of decimal results, and a string value for the unit |
Revision as of 12:08, 6 April 2010
Back to the Program-A-Day homepage
ProblemWrite a Java program Temp, that converts celcius to fahrenheit or vice versa.
Use the following formula to convert your units F = 9C/5 + 32 |
...by students
An image or By Students section | |
---|---|---|
SolutionStart by importing the swing java package. import javax.swing.*;
Define your variables, we will need doubles in case of decimal results, and a string value for the unit double temperature, result; String unit;
unit = JOptionPane.showInputDialog("Enter the 1-character temperature you want to convert from c (Celcius) or f (Fahrenheit)") ; temperature = Integer.parseInt(JOptionPane.showInputDialog("Enter the current temperature in the units you speficied")); | ||
Code |