Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Converting Fahrenheit to Celsius

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Converting Fahrenheit to Celsius

    So here is my code.... i really need help with it. I am completely new to this and going through the book, I came up with this. I am trying to display the answer in celsius and farenheit. I want to enter a farenheit into the program and it comes out in celsius.

    import javax.swing.*;
    public class FahrenheitToCelsius
    {
    public static void main (string[] args)
    {
    double fahrenheit;
    double celsius;

    input = JOptionPane.showInputDialog
    (null,"Temperature in Farenheit");
    fahrenheit = Doube.parseDouble(input);

    celsius = (fahrenheit -32)*(5/9)

    JOptionPane.showMessageDialog
    (null,"The Temperature in Celsius is" + celsius);
    }
    }
    Last edited by remedys; August 22nd, 2012 at 01:14 AM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Converting Fahrenheit to Celsius

    So what is the problem?
    What error message do you get?

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Converting Fahrenheit to Celsius

    ----jGRASP exec: javac -g FahrenheitToCelsius.java

    ----jGRASP wedge2 error: command "javac" not found.
    ---- This command must be in the current working directory
    ---- or on the current PATH to use this function.
    ---- PATH is ";C:\Program Files (x86)\Java\jre7\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\Sys tem32\Wbem;C:\Windows\System32\WindowsPowerShell\v 1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem\".
    ----jGRASP: operation complete.

    lol and then when i happen to run it... It says

    no main methods, applets, or MIDlets found in file.

    im using the program JGrasp

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Converting Fahrenheit to Celsius

    Do you have javac installed?
    Open a terminal and type:
    javac -version
    If you have it installed, it will show the version number. If that is the case include it in your path.
    If it is not installed, install it.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Converting Fahrenheit to Celsius

    Thank you for helping . It worked after I did that and i had to change the code a little . I added String input; also I had to mess with the equation . It wouldn't let me use 5/9 I had to change it to .55 Any reasons why ?

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Converting Fahrenheit to Celsius

    Quote Originally Posted by remedys View Post
    It wouldn't let me use 5/9 I had to change it to .55 Any reasons why ?
    It what? jGRASP?

    What did "it" say in the error message I assume you saw? Warning perhaps?

    5/9 would never change so using .55 would just be a bit more optimized than doing an unnecessary division. I am just guessing jGRASP was being picky about it, but I have never used jGRASP or see the message (from jGRASP or other..).

  7. The Following User Says Thank You to jps For This Useful Post:

    remedys (December 3rd, 2012)

Similar Threads

  1. [SOLVED] Trouble with fahrenheit to celsius conversion.
    By HaHom Tsa Pfnuma in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 27th, 2012, 09:50 AM
  2. Won't display calculated fahrenheit and celsius when running.
    By smithmar in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 17th, 2012, 09:00 PM
  3. Temperature Table Celsius and Fahrenheit
    By Krodfish in forum Loops & Control Statements
    Replies: 2
    Last Post: February 2nd, 2012, 10:06 PM
  4. Conversions Between Celsius and Fahrenheit
    By baueml01 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 9th, 2011, 07:49 PM
  5. Replies: 4
    Last Post: May 1st, 2009, 03:32 PM