for loop - Basic Java Hangman -


Hey guys, I'm just starting to learn Java as my first programming language! In the classroom, we were appointed to create an original hanging game for a while and loop!

Whatever I have done

When the first estimate of user inputs assumes that the characters they were guessed were corrected but Still out and stating that I have recognized the wrong characters!

Support will be highly appreciated !! My question is, am I doing wrong in my code? I need to tell the user if his estimate is true or false.

My code:

  import cs1.Keyboard; Public class hangman {public static zero chief (string agre []) {int intimateCount = 0; Int accurance = 0; Boolean found this; Boolean solution; Four estimates, answers; String word; System.out.println ("Welcome to Hongman!"); System.out.println ("Enter a word for the opponent's guess!"); word = keyboard.readString (); While (estimator calculation & lt; = 6) {System.out.println ("Please enter any letter A-Z as your guess!"); Estimate = Keyboard Readers (); (Int i = 0; i & lt; word.length (); i ++) {if (estimate == word.charAt (i)) {System.out.println ("You guessed a correct letter is!"); CorrectGuess ++; System.out.println ("True Fault Count:" + Perfect Guess); Hull = false; } And if (estimate! = Word. ChartAut (I)) {System.out.println ("Sorry, this is a false guess!" + "Please try again!"); GuessCount ++; System.out.println ("Count Number:" + EstimateCount); Hull = false; }} If (correctGuess == word.length ()) {solved = true; System.out.println ("Congratulations!" + "You have Guessed the Word!"); }}}}   

This is what I have done so far and here is the output

  Welcome to hangman! Please enter a word for the opponent's guess! Hello, please enter your AZ as your guess! sorry! This is a false guess! Please try again! Calculate: 1 Sorry! This is a false guess! Please try again! Calculate: 2 You have guessed a correct letter! Calculate the correct fault: 1 You have guessed a correct letter! Correct estimate count: 2 Sorry! This is a false guess! Please try again! It looks like: 3 Please enter any letter A-Z as your guess!    

You define estimation each character for string and then display for each letter , instead, you should write a method that calculates the characters that match the input (it also handles those words which Repeat the letter). So,

  private static int countOf (string in, four ch) {int count = 0; For (four c: in. Cicarrere ()) {if (c == ch) {count ++; }} Return calculation; }   

Then you can call it,

  Estimate = Keyboard .readChar (); Int count = countOf (words, estimates); If (calculation> 0) {System.out.println ("You have guessed a correct letter!"); Right + = calculation; } Else {System.out.println ("Sorry! This is a unique idea! Please try again!"); Estimate ++;   

Edit You can use it to do this without the other method,

  Estimate = Keyboard .readChar (); Int count = 0; For (four c: in.toCharArray ()) {if (c == estimate) {count ++; }} If (calculation> 0) {System.out.println ("You have guessed a correct letter!"); Right + = calculation; } else {System.out.println ("Sorry! This is a unique idea! Please try again!"); Estimate ++;   

And, since you have not used it -

  char [] characters = E.T.carrere (); For (int i = 0; i & lt; chars.length; i ++) {if (character [i] == estimate) {count ++; }}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -