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 trialAlexander Nowak
498 PointsSetting the word to be guessed
Hi, instead of using the array method.
Can we not take user input from the console such as "enter your guess word' and then that sets the word to be guessed? an the the rest of the code runs.
1 Answer
Alex Johnson
6,067 PointsYou could use the Console class. Here's an example that you can copy and paste into a file named Example.java and run yourself:
public class Example
{
public static void main(String[] args)
{
System.out.print("Enter something: "); // Prompt user for input
String input = System.console().readLine(); // Assign that input to the variable "input"
System.out.println("You entered: " + input); // Print out what was entered
}
}
You could use a similar method to prompt the user for a guess and then use the guess as you see fit.