Results 1 to 2 of 2
- 01-02-2012, 11:06 PM #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.
Thank you in advance!Last edited by pbrockway2; 01-02-2012 at 11:21 PM. Reason: code tags added
- 01-02-2012, 11:16 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
Similar Threads
-
how can check input is double or integer?
By HearT.Hunt3r in forum New To JavaReplies: 6Last Post: 10-15-2011, 07:12 AM -
convert integer to double
By himanwish in forum New To JavaReplies: 4Last Post: 03-17-2011, 01:55 AM -
Adding an integer to a double?
By tokoolio in forum New To JavaReplies: 5Last Post: 01-17-2011, 06:57 PM -
how to read an integer of DOUBLE datatype with type casting
By amrmb09 in forum Advanced JavaReplies: 2Last Post: 12-14-2010, 08:01 PM -
How to extract integer value out of a double value?
By javaexplorer in forum AWT / SwingReplies: 4Last Post: 01-16-2010, 05:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks