Skip to content

Random Words Final Version

package mainapplication;
import java.util.*;
/*
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();
Reporting.RunReport();
}
}
class Words {
public static ArrayList<String> WordsList =new ArrayList<String>();
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"};
for (int j = 0; j < 19; j++) {
String word = "";
for (int i = 0; i < 5; i++) {
word = word + alphabet[rand.nextInt(alphabet.length)];
}
WordsList.add(word);
}
}
}
class Reporting{
// output the contents of ArrayList WordList
static ArrayList localCopy = Words.WordsList;
public static void RunReport(){
for (int i = 0; i < localCopy.size(); i++) {
System.out.println(localCopy.get(i));
}
}
}

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.