Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need help trying to add a double to my code

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help trying to add a double to my code

    Pretty much what im trying to accomplish, i need to write a program that figures out the distance between one point to another, using miles and feet..

    Heres how it has to look: "The distance from my uncles house is ___ miles, or ____ feet."

    I can get it to run if i add only whole miles..but when i try to add 8.5 miles, and compile, the program flips out..I know i need to use a double somewhere, but cant figure it out, here is my code..


    import java.util.Scanner; //required for input

    public class feetToMiles {
    public static void main (String[] args){
    //Create new scanner object called input
    Scanner input = new Scanner (System.in); //allows for input

    //Step1. Declare INPUT and Calculated Variables
    int feet = 0, extraFeet = 0;
    int miles = 0;
    final int MILES_TO_FEET = 5280;

    //Step2. Input any data
    System.out.println("CO116 Mitch Taggart"); //required for CO116
    System.out.print("Enter distance to uncle's house in miles >> ");
    miles = input.nextInt();

    //Step3. Calculate any data
    feet = miles * MILES_TO_FEET;


    //Step4. Display results
    System.out.println("the distance to my uncles house is " + miles + " miles, or " + feet + " feet.");




    }
    }


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Need help trying to add a double to my code

    change feet and miles to double. Than you can say nextDouble() instead of nextInt()

  3. The Following User Says Thank You to camel-man For This Useful Post:

    mok4200 (September 19th, 2014)

  4. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help trying to add a double to my code

    Quote Originally Posted by camel-man View Post
    change feet and miles to double. Than you can say nextDouble() instead of nextInt()

    Awesome! i tried changing the miles and feet to double instead of int, but i kept getting an error, i completely forgot about changing the nextInt() to nextDouble(), Thanks!

Similar Threads

  1. Help add something to my code please.
    By ace799 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 24th, 2014, 05:10 AM
  2. How to add strings to this Code?
    By HARMAN in forum Java Theory & Questions
    Replies: 3
    Last Post: June 8th, 2013, 08:00 PM
  3. Replies: 9
    Last Post: August 30th, 2012, 03:25 PM
  4. How to add buttons on this code
    By tarell85 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 18th, 2011, 07:08 AM
  5. need to add a Double Button to the code
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: August 5th, 2010, 11:19 AM