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

1. Member Join Date
Oct 2014
Posts
20
Rep Power
0

## 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 ??  Reply With Quote

2. ## Re: Write a program to print out the Fahrenheit-Celsius conversion table Originally Posted by skj 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  Reply With Quote

3. Member Join Date
Oct 2014
Posts
20
Rep Power
0

## 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  Reply With Quote

4. Member Join Date
Oct 2014
Posts
20
Rep Power
0

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

May be I have to put this  Reply With Quote

5. ## 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  Reply With Quote

#### Posting Permissions

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