AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
3. Our Experts are looking for yours ?.

# programming-basics: Farenheit and Celcius

 It is required to calculate the Fahrenheit equivalent of 49 degree celcius. Use the following steps to write the program a) Declare two double variables fahr and celcius b) Assign the value of 49.0 to celcius c) multiply celcius by 9, divide by 5 and then add 32 to it d) Assign the above evaluation expression to the variable fahr e) Print the value of fahr using the statement System.out.printf("%5.2f\n", fahr) programming x 168basics x 171 Posted On : 2017-02-05 11:11:41.0 Raksha 2510 2

 public class CelciusToFarenheit { double fahr,celcius; public static void main(String[] args) { CelciusToFarenheit obj=new CelciusToFarenheit(49.0); obj.fahr=obj.convertCelciusToFarenheit(obj.celcius); System.out.printf("%5.2f\n", obj.fahr); } CelciusToFarenheit(double celcius){ this.celcius=celcius; } public double convertCelciusToFarenheit(double celcius){ return (celcius*9/5)+32; } } Posted On : 2017-02-06 23:54:48 Satisfied : 1 Yes  0 No Rishi Kumar 523188222642Reply This Thread 4
obj.fahr=obj.convertCelciusToFarenheit(obj.celcius);
Error in this line. Please verify.
Raksha
25  1  0
Posted On :2017-02-11 20:53:16.0
It is because the printing statement should be System.out.printf("%5.2f\n", fahr) and not obj.fahr
Raksha
25  1  0
Posted On :2017-02-11 21:19:43.0
public class CelciusToFarenheit {
public static void main(String[] args) {
double fahr,celcius;
celcius=49.0;
fahr=(celcius*9/5)+32;
System.out.printf("%5.2f\n",fahr);
}
}
Rishi Kumar
523  1882  22642
Posted On :2017-02-13 01:42:05.0