JAVA生成随机语句

年夜雪

关注

阅读 62

2022-02-16

public class Doobe {
	public static void main(String[] args)
	{
		String[] wordListOne = {"24/7", "B-To-B", "smart", "win-win"};
		String[] wordListTwo = {"sticky", "branded", "focused", "aligned"};
		String[] wordListThree = {"process", "solutino", "space", "vision"};

		//计算字符数组长度
		int oneLength = wordListOne.length;
		int twoLength = wordListTwo.length;
		int threeLength = wordListThree.length;

		//产生随机数
		int rand1 = (int)(Math.random() * oneLength);
		int rand2 = (int)(Math.random() * twoLength);
		int rand3 = (int)(Math.random() * threeLength);

		//组合语句
		String phtase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];

		//输出
		System.out.println("what we need is a " + phtase);
	}
}

精彩评论(0)

0 0 举报