Results 1 to 3 of 3
  1. #1
    Chiefo is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Default I am having a hard time with given a value and then multiplying it.

    I have a program where the user enters in the miles and then it is supposed to get multiplied by feet but I keep getting this error.

    GetUserInfo.java:12: error: bad operand types for binary operator '*'
    int total = name * feet;
    ^
    first type: String
    second type: int
    1 error

    This is my code so far, any help would be greatly appreciated :)

    import java.util.Scanner;
    public class GetUserInfo
    {
    public static void main(String[] args)
    {
    String name;
    int miles;
    Scanner inputDevice = new Scanner(System.in);
    System.out.print("Please enter the distance from your house to GRCC in Miles >> ");
    name = inputDevice.nextLine();
    int feet = 5280;
    int total = name * feet;
    System.out.println("The distance from your house to GRCC is " + miles +
    " or " + total + " feet.");
    }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: I am having a hard time with given a value and then multiplying it.

    You are trying to multiply a String by and int (e.g name * feet). You can't do that. Nor does it
    make sense to multiply a name by some value.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Chiefo is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Default Re: I am having a hard time with given a value and then multiplying it.

    I figured it out Jim. Thank you for the quick response. It is my first semester dealing with programming and some concepts are still trying to get memorized.

Similar Threads

  1. Regex giving me a hard time
    By tzeus in forum New To Java
    Replies: 4
    Last Post: 04-19-2014, 10:31 AM
  2. Having a hard time figuring this out! Please help.
    By syngine90 in forum New To Java
    Replies: 2
    Last Post: 12-19-2012, 10:31 AM
  3. HELP me with Binary Search Tree. hard time on it.
    By xajaxworldx in forum Advanced Java
    Replies: 4
    Last Post: 05-06-2011, 05:59 AM
  4. Static (having a hard time)
    By maknib in forum New To Java
    Replies: 4
    Last Post: 11-02-2010, 07:05 AM
  5. Extreme nooby having hard time with this app
    By asterix350z in forum New To Java
    Replies: 2
    Last Post: 12-05-2007, 07:24 PM

Posting Permissions

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