[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:Faiz,
Welcome to CodeRanch! I added [ code ] tags to make the code easier to read.
I think the problem is here:
In Java, we are suppose to use a method to compare Strings:
The difference is that == compares whether the same memory is used but equals() compares the actual values. == works fine for primitives like int. You know it is a primitive because the type name begins with a lowercase.
faiz jethwa wrote:If you are able to provide the solution, please can you also write me a few lines of explanation to go with the code so I can learn from this exercise.
Simply posting code will deprive the OP of the chance to learn fpr themselves. Don't be annoyed with me, but I have pulled rank and deleted your post. FJ will learn better by working out the answer.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Campbell Ritchie wrote:Faiz Jethwa welcome to the Ranch again.
Tthere is an explanation about the == operator here. To put it simply, == doesn't work on reference types.
Please take note of what you were told about the code button. Such code with the formatting hidden is difficult to read.
Lakshya Gupta welcoke to the Ranch
Please read this which appears on this forum:-Simply posting code will deprive the OP of the chance to learn fpr themselves. Don't be annoyed with me, but I have pulled rank and deleted your post. FJ will learn better by working out the answer.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
It still need editing, I am afraid. You need to remove the unnecessary comments, and also get the indentation right. Lost all those multiple blank lines which don't add to legibility.faiz jethwa wrote: . . .
Here is the final solution. . . .