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 Delivering the MVP Arrays and Command Line Arguments

I need computer to choose random word

What if I do not want to input answer as command line and wants computer to generate random word, how should i Do it?

1 Answer

Chris Tvedt
Chris Tvedt
3,795 Points

You would have to make a list of words to take from, if you want a word that has meaning. If you just want "n"-number of letters to be a word, but with no meaning. You need to have a look at ASCII-tables and stuff like that. I do not want to give away to much here. Psudocode for the first option would be:

import java.util.Random;

Random rand = new Random();

listOfWords = words.....

randomly generate a number between 0 - listOfWords.size()-1

input = listOfWords.get(randomly generated number)

Hope this gives you something to work on.