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: Celsius to fahrenheit vice versa

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Celsius to fahrenheit vice versa

    Hello again guys,

    I am having some trouble here not sure what is going on. I have gotten my program to show Celsius to Fahrenheit. However, it is not showing Fahrenheit to Celsius. I am trying to put it into chart form as well.

    Below is code:

           public static void main(String[] args) {
                java.util.Scanner input = new java.util.Scanner(System.in);
                    System.out.println(" ");
     
     
     
     
               for (double i = 31; i < 41; i++) {
        System.out.println("Celcius: " + i + " is " + celsiusToFahrenheit(i) + " in Fahrenheit");
    }
     
            for (double f = 120; f < 104; f++){
              System.out.println("Fahrenheit: " + f + " is " + fahrenheitToCelsius(f) + " in Celsius");}
            }
     
     
     
     
           public static double celsiusToFahrenheit(double i) {
                return (9.0 / 5) * i +32; 
              } 
     
           public static double fahrenheitToCelsius(double f) {
                return (5.0 / 9) * f - 32;
           }
     
     
     
        }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,503
    My Mood
    Mellow
    Thanks
    153
    Thanked 610 Times in 597 Posts

    Default Re: Celsius to fahrenheit vice versa

    Think about this:

    for (double f = 120; f < 104; f++)

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Celsius to fahrenheit vice versa

    Dont think I was.

    I now have

    for (double f = 120; f < 30; f++)

    Regardless, it isn't even printing out...

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,503
    My Mood
    Mellow
    Thanks
    153
    Thanked 610 Times in 597 Posts

    Default Re: Celsius to fahrenheit vice versa

    You haven't thought enough about that for statement, the old or the new. When will f be less than 104 or less than 30. Maybe . . . . . I know, NEVER.

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Celsius to fahrenheit vice versa

    haha.... wow, well thank you.

    I think I should have it from here.

    As usual thanks for your help.

    --- Update ---

    Actually while I have you here, how do I separate them in chart form


    Celsius Fahrenheit | Fahrenheit Celsius
    -----------------------------------------------

    x x x x

    I am getting the results I want and I have the top bar of the chart setup. I just do not know how to align the Fahrenheit into Celsius(right side)

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 159 Times in 150 Posts

    Default Re: Celsius to fahrenheit vice versa

    To format output you can use the String.format method or the printf method.
    Improving the world one idiot at a time!

Similar Threads

  1. [SOLVED] Converting Fahrenheit to Celsius
    By remedys in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 23rd, 2012, 03:26 AM
  2. [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
  3. 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, 08:00 PM
  4. Temperature Table Celsius and Fahrenheit
    By Krodfish in forum Loops & Control Statements
    Replies: 2
    Last Post: February 2nd, 2012, 09:06 PM
  5. 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