下面直接贴上代码:
public class PhraseOMatic { public static void main(String[] args) {/*单词短语*/ String[] wordListOne = {"孤独", "自由", "迷惘", "坚强", "绝望", "青春", "迷茫", "光明", "理想", "荒谬"}; String[] wordListTwo = {"生命", "路", "夜", "天空", "星空", "孩子", "雨", "石头", "鸟", "瞬间", "桥"}; String[] wordListX = {"正在", "已经", "一直", "无法"}; String[] wordListThree = {"爱着", "碎灭", "哭泣", "死去", "飞翔", "梦想", "祈祷", "离去", "再见", "埋葬"};/*计算每组有多少个术语*/ int oneLength = wordListOne.length; int twoLength = wordListTwo.length; int threeLength = wordListThree.length; int xLength = wordListX.length;/*产生随机数*//*输出*/ System.out.println("一首现代诗产生了:"); for (int i = 0; i < 4; i++) { int rand1 = (int) (Math.random() * oneLength); int rand2 = (int) (Math.random() * twoLength); int rand3 = (int) (Math.random() * threeLength); int randx = (int) (Math.random() * xLength); String phrase = wordListOne[rand1] + "的" + wordListTwo[rand2] + wordListX[randx] + wordListThree[rand3]; System.out.println(phrase); } }}
下面是运行后生成的几首现代诗:
Connected to the target VM, address: '127.0.0.1:49818', transport: 'socket'一首现代诗产生了:荒谬的夜一直梦想孤独的路正在再见光明的桥正在再见自由的鸟一直碎灭Disconnected from the target VM, address: '127.0.0.1:49818', transport: 'socket'
Process finished with exit code 0
Connected to the target VM, address: '127.0.0.1:49840', transport: 'socket'一首现代诗产生了:绝望的星空正在碎灭迷茫的生命无法爱着青春的瞬间一直埋葬青春的夜一直爱着Disconnected from the target VM, address: '127.0.0.1:49840', transport: 'socket'
Process finished with exit code 0
Connected to the target VM, address: '127.0.0.1:49644', transport: 'socket'一首现代诗产生了:坚强的鸟一直爱着理想的雨正在再见光明的鸟正在离去理想的瞬间一直碎灭Disconnected from the target VM, address: '127.0.0.1:49644', transport: 'socket'
Process finished with exit code 0
这个让我想起了那个6行代码的人工智能:
public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); String str; while (true) { str = sc.next().replace("吗", "").replace("?", "!").replace("?", "!"); System.out.println(str); }}
下面是我尝试和这个“人工智能”对话