Skip to content

Random Words version 2

package mainapplication;
/*
generate 20 random words.
Store these words in an Array List.
Use NetBeans and paste your code in the box below:
*/
public class MainApplication {
public static void main(String[] args) {
Words.Run();
}
}
class Words{
public static void Run(){
java.util.Random rand = new java.util.Random();
String[] alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
// let's make our words 5 characters in length
String word = "start:";
for (int i = 0; i < 5; i++) {
word = word + alphabet[rand.nextInt(alphabet.length)] ;
}
// trace debug message: You could also write this out to a Text File
System.out.println(word);
}
}

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.