Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Java Hangman Assignment
    text
    copied!<p>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 someone and the other person has to guess the word but they dont see the word so it displays it like this for example (if the word is aardvark)<br /></p> <p>* * * * * * * *</p> <p>Then the user inputs a letter and if its part of the word it then displays those letters, example:<br /></p> <p>Enter letter: a<br /> a a * * * a * *</p> <p>Enter letter: k<br /> a a * * * a * k</p> <p>Enter letter: r<br /> a a r * * a r k </p> <p>And so one...so yeah I've been stuck on this for a while and I REALLY need help Thanks</p> <p>P.S: This is an intro class so all I know so far are loops (for, while, do while etc), if, if/else, switch statements etc.</p> <pre><code>import java.util.Scanner; public class ass_2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // public static final Comparator&lt;secretWord&gt; CASE_INSENSITIVE_ORDER; int attempts = 10; int wordLength; boolean solved; Scanner userInput = new Scanner(System.in); System.out.println("OK Guessing Player ... turn around, while your friend enters the word to guess!\n"); System.out.println("Other Player ‐ Enter your word (letters only, no repeated letters and not case sensitive):"); String secretWord = userInput.next(); // 20 blank spaces WITH a for loop, we're smart! for(int i = 1; i &lt;= 20; i++) System.out.print("\n"); Scanner userLetter = new Scanner(System.in); String letter; System.out.print("Word to date: "); for (int i = 0; i &lt; secretWord.length(); i++) { System.out.print("*"); } while (attempts &lt;= 10 &amp;&amp; attempts &gt; 0) { System.out.println("\nAttempts left: " + attempts); System.out.print("Enter letter: "); attempts--; } System.out.println("\n---------------------------"); System.out.println("Sorry you didn't find the mystery word!"); System.out.println("It was \"" + secretWord + "\""); } </code></pre> <p>}</p> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload