What did i do wrong? Was I suppose to declare celtemp as constant? I was thinkin
ID: 3528000 • Letter: W
Question
What did i do wrong? Was I suppose to declare celtemp as constant? I was thinking that it will be an integer. How do I make my program run correctly? public class TemperatureConversion { public static void main( String [] args ) { int celtemp; int fahtemp; celtemp = 5/9 * (fahtemp - 32); System.out.println("temp in celsius is" + celtemp); // convert Celsius temperature back to Fahrenheit fahtemp = (9/5) * (celtemp + 32); //output Fahrenheit temperature to check correctness System.out.println("temp in fahrenheit is" + fahtemp);Explanation / Answer
public class TemperatureConversion {
public static void main( String [] args ) {
int celtemp; // it should be float celtemp ;
int fahtemp; // it should be float fahtemp;
celtemp = 5/9 * (fahtemp - 32);
System.out.println("temp in celsius is" + celtemp);
// convert Celsius temperature back to Fahrenheit
fahtemp = (9/5) * (celtemp + 32); //output Fahrenheit temperature to check correctness
System.out.println("temp in fahrenheit is" + fahtemp);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.