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 6 of 6

Thread: New program error help

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Location
    USA
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default New program error help

    I just started programming yesterday, and I have been making little programs to learn some algorithms and the syntax of java. I tried making a program that could convert metric units into the American system. Whenever I try to compile the code, it shows up as an "incompatible type" error. I know this is probably a very obvious answer to most of you, but I can't figure it out.

    import java.util.Scanner;
    public class MetricToAmerican
    {
    public static void main(String[] args)
    {
    Scanner scan = new Scanner(System.in);
    System.out.println("\fWhat measurement would you like to convert into US system? \ncelsius, meter, or kilogram ");
    String measurement = scan.nextLine();
    {
    if (measurement = "celsius") {
    System.out.println("\fWhat is the temperature in degrees Celsius? ");
    double celsius = scan.nextDouble() ;
    double fahrenheit = celsius * 1.8 + 32 ;
    System.out.println("\fThe temperature is " + fahrenheit + " degrees Fahrenheit");
    } else if (measurement = "meter") {
    System.out.println("\fWhat is the length in meters? ");
    double meter = scan.nextDouble() ;
    double feet = meter * 3.28 ;
    System.out.println("\fThe length is " + feet + " feet");
    } else if (measurement = "gram") {
    System.out.println("\fWhat is the weight in kilograms? ");
    double kilogram = scan.nextDouble() ;
    double pound = kilogram * 2.20462 ;
    System.out.println("\fThe weight is " + pound + " pounds");
    } else {
    System.err.println("PLEASE TYPE CELSIUS METER OR KILOGRAM");
    }
    }
    }
    }

    So if you know what s wrong with this program can you please say what is wrong and maybe how to fix it so I can learn from my mistakes. Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New program error help

    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    rmcm (August 31st, 2014)

  4. #3
    Junior Member
    Join Date
    Aug 2014
    Location
    USA
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: New program error help

    error message: "incompatible types"
    if (measurement = "celsius") {

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New program error help

    Use the equals() method to compare Strings.

    BTW:
    The compare for equals operator is ==
    The assignment operator is =
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    rmcm (August 31st, 2014)

  7. #5
    Junior Member
    Join Date
    Aug 2014
    Location
    USA
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: New program error help

    Could you give an example of how I would use that equals method in the program

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New program error help

    Pass this to your favorite search engine: java equals method
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 8
    Last Post: August 17th, 2014, 12:31 PM
  2. My program has a error, please help me!
    By EdgeThach in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 17th, 2014, 10:46 AM
  3. Program Error - Please help
    By Optimus_Prime in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 22nd, 2014, 10:03 AM
  4. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 24th, 2013, 02:49 PM
  5. Error of data types and type casting in java program
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 2nd, 2009, 10:22 AM