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

1. Member
Join Date
Jan 2012
Posts
8
Rep Power
0

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

Java 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.

Last edited by pbrockway2; 01-03-2012 at 12:21 AM. Reason: code tags added

2. ## 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•