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 4 of 4

Thread: write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20

    write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20 and convert to farenheit.

    I have to use doubles for Celsius and Fahrenheit and in the formula.
    I get a runtime error with the following displayed:

    I will display a table of temperatures in their Celsius and Farenheit equivalents.
    celsius farenheit
    --------------------

    /* This is my fifth homework */

    import java.util.*;
    import java.lang.*;
    import java.io.*;

    class TemperatureConversion
    {
    public static void main (String[] args) throws java.lang.Exception
    {
    double celsius; // Temperature in degrees Celsius minimum
    double farenheit; // Temperature in degrees Fahrenheit

    System.out.println("I will display a table of temperatures " +
    "in their Celsius and Farenheit equivalents.");

    //Display the degree equivalency headings.
    System.out.println("celsius\t\tfarenheit");
    System.out.println("--------------------");

    //Display the temperatures.
    for (celsius = 0; celsius <= 20; celsius++)
    {
    //Convert to Farenheit
    farenheit = celsius*(9/5)+32;

    //Display degrees in two equivalencies.
    System.out.printf("%d\t\t%.1f\n", celsius, farenheit);
    }
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20

    What error do you get? On what line?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20

    Look at the docs for java.util.Formatter:

    "Floating Point - may be applied to Java floating-point types: float, Float, double, Double, and BigDecimal"

    Now look at your formatter and see which conversion character you are using for both argument -- which are both doubles.

    BTW, don't use printf. Get in the habit of using String.format() directly.

    Also, "(9 / 5) + 32" will not result in a double literal. I'd create a class constant to use here:

    final double F_SCALE = (9d / 5d) + 32d;

    See: http://docs.oracle.com/javase/tutori...datatypes.html
    Last edited by jdv; September 30th, 2014 at 09:37 AM.

Similar Threads

  1. Replies: 2
    Last Post: October 25th, 2013, 06:31 AM
  2. Java Program ferinheight to celsius Table
    By jaxsonville187 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 9th, 2013, 12:39 AM
  3. Temperature Table Celsius and Fahrenheit
    By Krodfish in forum Loops & Control Statements
    Replies: 2
    Last Post: February 2nd, 2012, 10:06 PM
  4. Finding Multiple Equal Max Values in an Array
    By AbsolutelyNobody in forum Collections and Generics
    Replies: 4
    Last Post: October 30th, 2011, 03:07 AM
  5. TAKE & PUT VALUES INTO AN ORACLE TABLE THRU A LOOP
    By jai in forum Algorithms & Recursion
    Replies: 1
    Last Post: September 17th, 2011, 05:39 AM