0
点赞
收藏
分享

微信扫一扫

JAVA生成随机语句

年夜雪 2022-02-16 阅读 62
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 条评论