View Single Post
Old Jun 9th, 2005, 9:51 AM   #9
shangnyun
Programmer
 
shangnyun's Avatar
 
Join Date: Jun 2005
Posts: 34
Rep Power: 0 shangnyun is on a distinguished road
Quote:
Originally Posted by HeX
are you allowed to use JOptionPane ? if yes then:

import java.util.*;

public class TempConversion
{
    public static void main(String[] args)
    {
	double result;
	String degree;
	int input;
    	
	degree = JOptionPane.showInputDialog("Enter: \n C - Fahrenheit to Celsius\n F - Celsius to Fahrenheit");


	input = new Integer(JOptionPane.showInputDialog("Enter the degree:")).intValue();

	if(degree == "C" || degree == "c")
	{
			result = 5.0/9.0 * (input - 32);
			System.out.println(input + " Fahrenheit is " + result + " Celsius");
	}
	else if(degree == "F" || degree == "f")
	{
		result = 9.0/5.0 * input + 32;
		System.out.println(input + " Celsius is " + result + " Fahrenheit");
	}
	
    }
}
OMG... you helped me but also confused the shit out of me. I totally understand your logic in using only one variable for the degree integer, namely "input", but I'm confused why my book is using TWO variables, namely degreesC and degreesF.
And this is without Swing, so no JOptionPane
shangnyun is offline   Reply With Quote