PhraseOMatic java program

There are following way to make PhraseOMatic java program.

  • First, we find out how many words are in each list using ListOne.length method.
  • Generate 3 random numbers using random.nextInt() method in int type.
  • Now use this random numbers to build a phrase!
  • Print the phrase output.
import java.util.Random;

public class PhraseOMaticTest {
	public static void main(String[] args) {

		String[] wordListOne = { "java", "spring", "hibernate", "servlet" };
		String[] wordListTwo = { "svn", "git", "jenkins", "maven" };
		String[] wordListThree = { "kibana", "zookeeper", "dynatrace", "jira" };

		int oneLength = wordListOne.length;
		int twoLength = wordListTwo.length;
		int threeLength = wordListThree.length;

		Random random = new Random();

		int rand1 = random.nextInt(oneLength);
		int rand2 = random.nextInt(twoLength);
		int rand3 = random.nextInt(threeLength);

		String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
		System.out.println("Random phrase is a :- " + phrase);
	}
}

Output :-
Random phrase is a :- java svn dynatrace