Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By JosAH

Thread: Write a program to print out the Fahrenheit-Celsius conversion table

  1. #1
    skj
    skj is offline Member
    Join Date
    Oct 2014
    Posts
    20
    Rep Power
    0

    Default Write a program to print out the Fahrenheit-Celsius conversion table

    Hello, can someone help me with this :
    This is my program
    import java.util.Scanner;
    import java.text.DecimalFormat;

    public class Lab6 {
    public static void main(String[] args) {

    int F;
    double C = 0;

    Scanner input = new Scanner(System.in);

    F = input.nextInt();

    DecimalFormat df = new DecimalFormat(("00.00"));

    for (F = 0; F <= 9; F++) {

    C = (double) (F - 32) * (5 / 9);

    System.out.println(F + " degree Fahrenheit equal to :"
    + df.format(C) + " degree Celsius");
    }
    }
    }
    output
    0 1 2 3 4 5 6 7 8 9
    0 degree Fahrenheit equal to :-00.00 degree Celsius
    1 degree Fahrenheit equal to :-00.00 degree Celsius
    2 degree Fahrenheit equal to :-00.00 degree Celsius
    3 degree Fahrenheit equal to :-00.00 degree Celsius
    4 degree Fahrenheit equal to :-00.00 degree Celsius
    5 degree Fahrenheit equal to :-00.00 degree Celsius
    6 degree Fahrenheit equal to :-00.00 degree Celsius
    7 degree Fahrenheit equal to :-00.00 degree Celsius
    8 degree Fahrenheit equal to :-00.00 degree Celsius
    9 degree Fahrenheit equal to :-00.00 degree Celsius
    I don't know why the program is not calculating the C degree ??

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Write a program to print out the Fahrenheit-Celsius conversion table

    Quote Originally Posted by skj View Post
    C = (double) (F - 32) * (5 / 9);
    The numbers 5 and 9 are ints, so 5/9 == 0 (integer division). I think you can figure out the rest.

    kind regards,

    Jos
    skj likes this.
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    skj
    skj is offline Member
    Join Date
    Oct 2014
    Posts
    20
    Rep Power
    0

    Default Re: Write a program to print out the Fahrenheit-Celsius conversion table

    Thank you for replying ,I don't know how to fix this . I have added (Double) it supposed to work ?
    Kind regards
    Sarah

  4. #4
    skj
    skj is offline Member
    Join Date
    Oct 2014
    Posts
    20
    Rep Power
    0

    Default Re: Write a program to print out the Fahrenheit-Celsius conversion table

    May be I have to put this
    c= ((double)5/9)*(F-32) instead

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Write a program to print out the Fahrenheit-Celsius conversion table

    Instead of 5/9, how about 5.0/9.0? The division will be a division of doubles ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 16
    Last Post: 11-01-2013, 05:22 PM
  2. Replies: 6
    Last Post: 09-03-2012, 06:31 PM
  3. celsius to farenheit conversion program...
    By andrewsx in forum New To Java
    Replies: 3
    Last Post: 03-03-2010, 04:34 AM
  4. Help with fahrenheit to celsius conversion
    By java_is_killingme in forum New To Java
    Replies: 4
    Last Post: 03-07-2009, 11:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •