java - Mastermind game if statement problems -


i trying make when 2 or more of if statements work dont both print instead 2 in correct spot or more more works. im not sure if im suppose make more if statements of if suppose use statement or forloop.

               //if statements                 if (gameboard[0] == secret_code[0]) {                     system.out.println ("you have 1 in correct spot");     }                  if (gameboard[1] == secret_code[1]) {                     system.out.println ("you have 1 in correct spot");     }                 if (gameboard[2] == secret_code[2]) {                     system.out.println ("you have 1 in correct spot");     }                 if (gameboard[3] == secret_code[3]) {                     system.out.println ("you have 1 in correct spot");     }  } } 

the solution "in words"

instead of checking whether code correct in each spot , printing immediately, consider creating variable count number of times peg has been correct. don't print until know value of variable has taken consideration of elements of secret_code (a way (the "right" way)) loop through secret_code array , use new variable count each time code correct.

finally, print message user using variable holds information how many correct.

i won't include example code can sure implement , understand :-)


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -