I'm a tad confused on a homework assignment. I'm supposed to write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. I got the loop to work just fine, but I'm supposed to display the results of the loop in a TextArea box. The teacher went over it once in class, but I'm having trouble grasping it.
Here's what I wrote so far:
package celsiustofahrenheit;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class CelsiusToFahrenheit {
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "This program will display a table of Celsius "
+ "temperatures 0 through 20 and their Fahrenheit equivalents.");
int Fahrenheit = 0;
int Celcius = 0;
JTextArea text;
JScrollPane pane;
String input = "";
while (Celcius<20)
{
Fahrenheit = Celcius*9/5+32;
Celcius++;
JOptionPane.showMessageDialog(null, "Celcius = " + Celcius + "");
JOptionPane.showMessageDialog(null, "Fahrenheit = " + Fahrenheit + "");
}
text = new JTextArea(5,15);
text.setText(input);
pane = new JScrollPane(text);
JOptionPane.showMessageDialog(null, pane);
}
}
I would like to know what I'm doing wrong. Thank you.