How to write an program that converts a temperature given Fahrenheit to centigrade?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shon1228
    New Member
    • Mar 2010
    • 1

    How to write an program that converts a temperature given Fahrenheit to centigrade?

    import java.util. Scanner;

    public class Temp{
    {
    public static void main (String [] args){
    //Have the user to enter a temperature in fahrenheit
    {
    System.out.prin tln ("Enter a temperature");

    This is all I have so far ...any suggestions? I know I have to use scanner reading, but I do not know where.
  • anurag275125
    New Member
    • Aug 2009
    • 79

    #2
    try this..

    Code:
    import java.util.*;
    public class TemperatureConversion 
    {
    	public static void main(String args[])
    	{
    		float f,c;
    		Scanner sc=new Scanner(System.in);
    		System.out.println("Enter temperature in fahrenheit : ");
    		f=sc.nextFloat();
    		c=((f-32)*5)/9;
    		System.out.println("Celsius Temperature : "+c);
    	}
    }

    Comment

    • pbrockway2
      Recognized Expert New Member
      • Nov 2007
      • 151

      #3
      That doesn't leave much fun for shon!

      If he/she hasn't done so, reading the section in the Java Tutorial on scanning (along with nearby sections) may be useful.

      Comment

      Working...