Java code problems | Sololearn: Learn to code for FREE!


Java code problems It must output a price if you input correct model but it doesn't. Do you know where problem is? Don't forget to give me a questions if there is any.

9/21/2018 1:05:07 PM

Oleg Storm

5 Answers

New Answer


Oleg Storm The main problem with your code is that you are using '==' operator to compare the user input with carModel when you should be using '.equals()' function to compare them. To quote GeeksforGeeks - "== checks if both objects point to the same memory location whereas .equals() evaluates to the comparison of values in the objects." If you want your code to print the price of the car if the user entered the correct car model then you need to replace "System.out.println(car.CarModel(model));" with "System.out.println(car.Price());" This should get back on track. Let me know either way.


I really didn't know what this (==) means till now🤤, it was so helpful! Thanks a lot for your answer, ODLNT😄.


0 My ultimate thanks to you, guys😊