• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array issue  RSS feed

 
John Morgan
Ranch Foreman
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a simple MasterMind game where you guess the pegs and the order they are in... I am doing this to teach myself about arrays and calling information from one class to another.

I cannot figure out what I am doing wrong here.... I can see the code run with break points and I get the correct responses for what is in each slot, and the pegs for each slot but for some reason the comparison always comes back negative.

Any ideas...
 
Carey Brown
Saloon Keeper
Posts: 3317
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When comparing Strings don't use == use equals(). == only compares the reference to see if both references refer to the same item. The equals() method actually compares the content to see if they are equal.
 
John Morgan
Ranch Foreman
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked... thank you very much.

Carey Brown wrote:When comparing Strings don't use == use equals(). == only compares the reference to see if both references refer to the same item. The equals() method actually compares the content to see if they are equal.
 
John Morgan
Ranch Foreman
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course it helps that I was not using guess 1 for everything....
John Morgan wrote:That worked... thank you very much.

Carey Brown wrote:When comparing Strings don't use == use equals(). == only compares the reference to see if both references refer to the same item. The equals() method actually compares the content to see if they are equal.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!