-2

I am reasonably experienced with programming, but not specifically in Java. I am coming across the following error when working in eclipse. My code is the following:

My code

I have used the debug function, and it reports that carbonPrefix is pent, but that carbon stays at 0 throughout. Like I said, I am a novice to Java and Eclipse, so I may not be using the debug function to it's full extent.

For anybody that's interested, this the start of code where you input the name of an alkane and it tells you the formula. It worked in Javascript and I'm just trying to translate it into Java.

Thank you all so much!

Mira Welner
  • 409
  • 4
  • 15
  • 1
    Please put the code in text form and make sure it's complete. – ChiefTwoPencils Jun 20 '18 at 00:30
  • `==` for objects (including String) tests for *identity*, not equality. Two different Strings with the same content are not "the same thing', because they use different regions of memory for their content. See Jim Lewis' link for what do to instead. – Mike 'Pomax' Kamermans Jun 20 '18 at 00:34

1 Answers1

1

you have to use

carbonPrefix.equals("pent");

in java == operator used to compare two object references and the method equals() is used to compare two strings to determine whether they are equal or not.

Sundeep
  • 452
  • 2
  • 12