Simple Java Hangman Assignment

后端 未结 5 1980
夕颜
夕颜 2021-02-06 06:05

I\'m stuck on a java assignment for a class where we need to make a Hangman game but a REALLY BASIC one (It\'s an intro to Java class). Basically I have a word entered by someon

5条回答
  •  [愿得一人]
    2021-02-06 06:32

    It's not so stupid, the aim is to make you more able to come up with original solutions.
    Here, for example, you are working with Strings, so it would make sense to go on the javadoc and see the String page, to see if any function could come handy.
    Next, comes the logic : you get a "String" input, then only get "char"s input and you have to compare a String with a char. So, the best way is to compare each "char" of your "String".
    You can't use arrays ? Ok then, you can also use loops and two certain String functions (you already knows length(), which is one of the two), which will give the same result as going through a array to test each of its element.
    The game end if no * is displayed or if there is no attempts left, so the player can try as long as neither of those conditions are true.

提交回复
热议问题