AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
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 168
basics x 170
Posted On : 2017-02-05 11:11:41.0
profile Raksha - anyforum.in Raksha
2510
up-rate
2
down-rate

Answers



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
profile Rishi Kumar - anyforum.in Rishi Kumar
523188221630
Reply This Thread
up-rate
4
down-rate
Comments
obj.fahr=obj.convertCelciusToFarenheit(obj.celcius);
Error in this line. Please verify.
profile Raksha - anyforum.in Raksha
25  1  0
Posted On :2017-02-11 20:53:16.0
Leave a Comment
It is because the printing statement should be System.out.printf("%5.2f\n", fahr) and not obj.fahr
profile Raksha - anyforum.in Raksha
25  1  0
Posted On :2017-02-11 21:19:43.0
Leave a Comment
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);
}
}
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1882  21630
Posted On :2017-02-13 01:42:05.0
Leave a Comment
Thank you prince raj!
profile Raksha - anyforum.in Raksha
25  1  0
Posted On :2017-02-13 17:59:46.0
Leave a Comment



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in