1 package com.hfjava5; 2 3 public class PhraseOMatic { 4 public static void main(String[] args) { 5 String[] wordListOne = {"24/7", "multi-Tier", "30,000 foot", "B-to-B", 6 "win-win", "front-end", "web-based", "pervasive", "smart", "six-sigma", 7 "critical-path", "dynamic"}; 8 String[] wordListTwo = {"empowered", "sticky", "value-added", "oriented", "centric", 9 "distributed", "clustered", "branded", "outside-the-box", "positioned", "networked", 10 "focused", "leveraged", "aligned", "targeted", "shared", "cooperative", "accelerated"}; 11 String[] wordListThree = {"process", "tipping-point", "solution", "architecture", "core competency", 12 "strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission"}; 13 14 // 计算每一组有多少个名词术语 15 int oneLength = wordListOne.length; // 12 16 int twoLength = wordListTwo.length; // 18 17 int threeLength = wordListThree.length; // 12 18 19 /* Java本身有一组立即可用的数学方法 20 * random()会返回介于0与1之间的值,所以需要将此值乘以数组的元素数量(数组的大小),然后取*整数值*(第4章) 21 * 如果需要对任何浮点数取整数值也是用这样的方法转换数据类型 22 */ 23 // 产生随机数字 24 int rand1 = (int) (Math.random() * oneLength); // 0-12 25 int rand2 = (int) (Math.random() * twoLength); // 0-18 26 int rand3 = (int) (Math.random() * threeLength); // 0-12 27 28 // 组合出专家术语 29 String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3]; 30 31 System.out.println("What we need is a " + phrase); 32 } 33 }
时间: 2024-12-09 03:14:11