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 Java Objects (Retired) Delivering the MVP Arrays and Command Line Arguments

Where does the "please enter a word" prompt come up?

In this exercise we added System.out.println("Please enter a word."); to start the Hangman game with a word other than 'treehouse'. Where/when will this prompt the user? I have yet to see it when the program is run. Maybe it has something to do with my workspace not updating my changes :( but even in the video the prompt comes up not.

public class Hungman  {
  public static void main(String[] args)  {
    //Begin the work here:
    if (args.length == 0 )   {
      System.out.println("Please enter a word.");
      System.exit(0);
    }
    Game game = new Game(args[0]);
    Prompter prompter = new Prompter(game);
    prompter.play();
  }
}

Who ate pi on 3.14.15 @ 9:26?

2 Answers

Harry James
Harry James
14,780 Points

Hey matsum0t0!

That piece of code will be printed onto the system console. Note that the code is in an if statement and only runs if no arguments are entered. Craig doesn't actually run the code without any arguments but, if you want to, you can do so with

clear && javac Hangman.java && java Hangman

(Craig's code is:)

clear && javac Hangman.java && java Hangman durian

with durian being the argument.


Hope it helps and, if you have any more questions, give me a shout :)

The prompt doesn't come up, because you will have to enter the word you want after

clear && javac Hangman.java && java Hangman

The prompt will only come up if you don't type anything after the above.