Results 1 to 2 of 2
  1. #1
    Keke101 is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default 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(;
        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

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power

    Default 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

  1. how can check input is double or integer?
    By HearT.Hunt3r in forum New To Java
    Replies: 6
    Last Post: 10-15-2011, 07:12 AM
  2. convert integer to double
    By himanwish in forum New To Java
    Replies: 4
    Last Post: 03-17-2011, 01:55 AM
  3. Adding an integer to a double?
    By tokoolio in forum New To Java
    Replies: 5
    Last Post: 01-17-2011, 06:57 PM
  4. Replies: 2
    Last Post: 12-14-2010, 08:01 PM
  5. How to extract integer value out of a double value?
    By javaexplorer in forum AWT / Swing
    Replies: 4
    Last Post: 01-16-2010, 05:32 AM

Posting Permissions

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