前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用代码生成一首现代诗~

用代码生成一首现代诗~

作者头像
爱敲代码的猫
发布2019-12-02 19:48:05
9010
发布2019-12-02 19:48:05
举报
文章被收录于专栏:爱敲代码的猫

下面直接贴上代码:

代码语言:javascript
复制
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);        }    }}

下面是运行后生成的几首现代诗:

代码语言:javascript
复制
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
代码语言:javascript
复制
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
  • Three
代码语言:javascript
复制
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行代码的人工智能:

代码语言:javascript
复制
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);        }}

下面是我尝试和这个“人工智能”对话

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-11-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 爱敲代码的猫 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档