Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having trouble printing celsius part of this, either something is wrong wit

ID: 441632 • Letter: I

Question

I am having trouble printing celsius part of this, either something is wrong with the method or how I am typing it when I am calling the method(fToC). Everytime I print this out normally it prints in columns like I want it to but the celsius either prints out as -0.0 or 0.0. I am not quite sure what I am doing wrong. They have to stay in columns like this and I would like to keep the same formatting I have. public class Temperatures { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please input the town and initials of the state. "); String townAndState = input.nextLine(); int num = 0; Scanner input2 = new Scanner(System.in); System.out.println("Please input the temperatures in fahrenheit and put -999 when finished. "); double[] temperature = new double [10]; for(int i = 0; i < temperature.length; i++) { temperature[i] = input.nextDouble(); System.out.printf("%7.1f", temperature[i]); double celsius = fToC(temperature[i]); System.out.printf("%7.1f ", celsius); } } public static double fToC(double temperature) { double division = 5 / 9; double conversion = (temperature - 32) * division; return conversion; }

Explanation / Answer

Please rate with 5 stars. I found out the bug in your code. Here it is :) You should never use division of 2 integers like (5/9) because this is a division of 3 integers and the result will be the integer 0. To get the correct, result, just use (5/9.0). Cheers!