Results 1 to 2 of 2
- 08-05-2007, 11:14 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Converts from Fahrenheit to Celsius
Hi, Looking for a little help on writing a temperature conversion program that converts from Fahrenheit to Celsius. I should be able to enter the Fahrenheit temperature from the keyboard.
Then using a TextField it should display the converted temperature. Of course using the following formula for conversion:
Thanks.Java Code:Celsius = 5 / 9 * (Fahrenheit - 32)
- 08-06-2007, 05:52 AM #2
Java Code:import java.util.Scanner; import javax.swing.JOptionPane; public class Converter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String choice; do { System.out.println("enter fahrenheit"); int f = Integer.parseInt(scanner.nextLine()); int celsius = convert(f); String s = String.valueOf(f) + " = " + celsius + " celsius"; JOptionPane.showMessageDialog(null, s, "Converter", JOptionPane.PLAIN_MESSAGE); System.out.println("More? \"y\" or any key"); choice = scanner.nextLine(); } while(choice.equals("y")); scanner.close(); } private static int convert(int fahrenheit) { return 5*(fahrenheit - 32)/9; } }
Similar Threads
-
Fahrenheit to celsius
By lalithalydia in forum New To JavaReplies: 3Last Post: 02-05-2008, 07:50 AM -
farenheit to celsius
By lalithalydia in forum New To JavaReplies: 2Last Post: 02-02-2008, 08:44 AM -
Celsius Converter project
By jpdamigaman in forum NetBeansReplies: 3Last Post: 11-14-2007, 12:20 AM -
Converts a binary number to a decimal
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 09:57 AM


LinkBack URL
About LinkBacks

Bookmarks