# Change the integer variable to type double - is this right?

Printable View

• 01-03-2012, 12:06 AM
Keke101
Change the integer variable to type double - is this right?
Code:

```// Application Convert converts a temperature in Fahrenheit to // Celsius and a temperature in Celsius to Fahrenheit import java.util.Scanner; public class Convert {   public static void main(String[] args)   {     Scanner inData = new Scanner(System.in);     int fToC; // Place to store Celsius answer     int cToF; // Place to store the Fahrenheit answer     System.out.println("Enter a value to be converted "       + "from Fahrenheit to Celsius.");     fToC = Integer.parseInt(inData.nextLine());         System.out.print("Enter a value to be converted "       + "from Celsius to Farenheit.");     cToF = Integer.parseInt(inData.nextLine());     System.out.println(fToC + " in Fahrenheit is "        + ((double)(5 * (fToC - 32)/9)) + " in Celsius. ");         System.out.println(cToF + " in Celsius is "       + ((double)(9 * (cToF + 32)/5)) + " in Farenheit. ");                    } }```

My exercise for this is: Change the integer variable to type double and rerun the application with the same data you used in Exercise 3. I am not sure if I did this correctly and could use some help.

This does compile without error but, I am still not sure if this is what they are looking for.

Thank you in advance!
• 01-03-2012, 12:16 AM
sunde887
Re: Change the integer variable to type double - is this right?
The questions wording is a bit ambiguous, but that should be one valid approach. Your professor may also be talking of phiscally changing the type of variable, rather than casting it. Either is quite trivial, the one I suggested requires changing the declaration statement of the variables.