如何工作
3组单字随机跳出来排列组合输出
- 创建3个String的数组,用于保存术语。
- 随机挑出单字。首先要知道数组的长度n,再根据数组长度,然后选出介于0~n-1的随机数,最后获得单字。
- 创建专用术语,选出3个字用“+”将字符串链接在一起。
- 最后输出结果。
代码
import static java.lang.Math.random;
public class PhraseOMatic {
public static void main(String[] args) {
// 可随意加入其它术语
String[] wordListOne = { "24/7", "multiTier", "30,000 foot", "B-to-B", "win-win", "frontend", "web-based",
"pervasive", "smart", "sixsigma", "critical-path", "dynamic" };
String[] wordListTwo = { "empowered", "sticky", "value-added", "oriented", "centric", "distributed",
"clustered", "branded", "outside-the-box", "positioned", "networked", "focused", "leveraged", "aligned",
"targeted", "shared", "cooperative", "accelerated" };
String[] wordListThree = { "process", "tippingpoint", "solution", "architecture", "core competency",
"strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission" };
// 计算每一组有多少个名词
int oneLength = wordListOne.length;
int twoLength = wordListTwo.length;
int threeLength = wordListThree.length;
// 产生随机数字
int rand1 = (int) (random() * oneLength);
int rand2 = (int) (random() * twoLength);
int rand3 = (int) (random() * threeLength);
// 组合出专家术语
String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
// 输出
System.out.println("What we need is a " + phrase);
}
}