Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Getting Two Errors Not Sure How to Fix

The compiler is giving me two errors and I'm not sure what I'm doing wrong. Here is my code:

public class Hangman {

  public static void main(String[] args) {
    // Your incredible code goes here...
    if (args.length == 0) {
      System.out.println("Usage:   java Hangman <answer>");
      System.err.println("answer is required");
      System.exit(1);
    }
    Game game = new Game(args[0]);
    Prompter prompter = new Prompter(game);
    while (game.getRemainingTries() > 0) && !game.isWon()) {
      prompter.displayProgress();
      prompter.promptForGuess();
    }

    prompter.displayOutcome(); 
   }
}

Here is what the compiler says:

treehouse:~/workspace$ javac Hangman.java
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Hangman.java:12: error: illegal start of expression
while (game.getRemainingTries() > 0) && !game.isWon()) {
^
Hangman.java:12: error: ';' expected
while (game.getRemainingTries() > 0) && !game.isWon()) {
^
2 errors

David Pollard
David Pollard
4,324 Points

I may be wrong, but are the parenthesis correct here :-

while (game.getRemainingTries() > 0) && !game.isWon()) {

Should it be ....

while ((game.getRemainingTries() > 0) && !game.isWon()) {

hth

dp

1 Answer

alastair cooper
alastair cooper
30,617 Points

both expressions should be in the if parentheses, like so...

while (game.getRemainingTries() > 0 && !game.isWon()) {

The second error is probably caused by the compiler expecting a semi-colon because you closed the parentheses too early (although you would think it would expect an opening brace!)

hope this helps