大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要讲解了“怎么使用java和python制作一个专业术语学习机”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用java和python制作一个专业术语学习机”吧!
创新互联于2013年成立,是专业互联网技术服务公司,拥有项目网站制作、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元永平做网站,已为上家服务,为永平各地企业和个人服务,联系电话:13518219792首先,我们需要一些专业名词,制成词典,从专业名词中选出一些组合起来生成专业术语。
我决定从词典里选择4个组成专业术语,于是我做了4个词典。容量虽然不够大,但是当个玩具玩一玩还是够的。
下面是我的专业名词词典:
String[] word1 = {"可用的","禁用","127%","平衡","转移","4/3","2/7","78%","通用","限定"}; String[] word2 = {"RNA","DNA","串行设备","细胞","大容量","原虫","分离"}; String[] word3 = {"总线","病毒","编译","计算机","计算机病毒","移动","量产工具","培养皿","形态"}; String[] word4 = {"控制面板","作用器","日志","控制器","面板","用户","存储","管理员","域","尺","计数器"};
你可以在词典里加入你自己的专业名词。
接下来,我们需要随机数,以此从词典中选出词语。这里用到random方法:
int n1 = (int) (Math.random() * 10); //有一定经验者应该都看懂了吧 int n2 = (int) (Math.random() * 7); int n3 = (int) (Math.random() * 9); int n4 = (int) (Math.random() * 11);
接下来,把名词组合起来输出:
System.out.print("\n您生成的专业术语是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n");
这时,我想批量生成专业术语怎么办呢?
获取用户输入,需要多少个专业术语:
System.out.print("请输入要产生的专业术语的个数:");Scanner sc = new Scanner(System.in);
转化为int型:
int numbersc = sc.nextInt();
用计数器看看有没有输出完所需的专业术语:
int number = 0while(number < numbersc) { int n1 = (int) (Math.random() * 10); int n2 = (int) (Math.random() * 7); int n3 = (int) (Math.random() * 9); int n4 = (int) (Math.random() * 11); System.out.print("\n您生成的第" + (number + 1) + "个专业术语是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n"); number = number + 1; }
不断循环地运行:
while(true) { System.out.print("请输入要产生的专业术语的个数:"); Scanner sc = new Scanner(System.in); int numbersc = sc.nextInt(); int number = 0 while(number < numbersc) { int n1 = (int) (Math.random() * 10); int n2 = (int) (Math.random() * 7); int n3 = (int) (Math.random() * 9); int n4 = (int) (Math.random() * 11); System.out.print("\n您生成的第" + (number + 1) + "个专业术语是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n"); number = number + 1; } System.out.print("\n\n"); }
最后,给出完整代码:
pt.java:
import java.util.Scanner;public class pt { public static void main(String[] args) { String[] word1 = {"可用的","禁用","127%","平衡","转移","4/3","2/7","78%","通用","限定"}; String[] word2 = {"RNA","DNA","串行设备","细胞","大容量","原虫","分离"}; String[] word3 = {"总线","病毒","编译","计算机","计算机病毒","移动","量产工具","培养皿","形态"}; String[] word4 = {"控制面板","作用器","日志","控制器","面板","用户","存储","管理员","域","尺","计数器"}; while(true) { int number = 0; System.out.print("请输入要产生的专业术语的个数:"); Scanner sc = new Scanner(System.in); int numbersc = sc.nextInt(); while(number < numbersc) { int n1 = (int) (Math.random() * 10); int n2 = (int) (Math.random() * 7); int n3 = (int) (Math.random() * 9); int n4 = (int) (Math.random() * 11); System.out.print("\n您生成的第" + (number + 1) + "个专业术语是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n"); number = number + 1; } System.out.print("\n\n"); } } }
以及标题中承诺过的python3代码:
pt.py3
import random; word1 = ["可用的","禁用","127%","平衡","转移","4/3","2/7","78%","通用","限定"]; word2 = ["RNA","DNA","串行设备","细胞","大容量","原虫","分离"]; word3 = ["总线","病毒","编译","计算机","计算机病毒","移动","量产工具","培养皿","形态"]; word4 = ["控制面板","作用器","日志","控制器","面板","用户","存储","管理员","域","尺","计数器"]; while True: number = 0 numbersc = input("请输入要产生的专业术语的个数:") numbersc = int(scnumber) while number < numbersc: n1 = random.randint(0,9) n2 = random.randint(0,6) n3 = random.randint(0,8) n4 = random.randint(0,10) number2 = number + 1 number2 = str(number2) print("您生成的第" + number2 + "个专业术语是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n") number += 1;
赶快拿上代码,去到你的家人、朋友面前炫耀吧!
此处,给出一次运行结果(每次运行结果都不一样!):
请输入要产生的专业术语的个数:5您生成的第1个专业术语是:通用细胞计算机病毒控制器 您生成的第2个专业术语是:平衡原虫移动域 您生成的第3个专业术语是:2/7分离总线作用器 您生成的第4个专业术语是:平衡细胞量产工具尺 您生成的第5个专业术语是:通用大容量编译管理员 请输入要产生的专业术语的个数(:
赶快拿上代码,去到你的家人、朋友面前炫耀吧!
此处,给出一次运行结果(每次运行结果都不一样!):
请输入要产生的专业术语的个数:5您生成的第1个专业术语是:通用细胞计算机病毒控制器 您生成的第2个专业术语是:平衡原虫移动域 您生成的第3个专业术语是:2/7分离总线作用器 您生成的第4个专业术语是:平衡细胞量产工具尺 您生成的第5个专业术语是:通用大容量编译管理员 请输入要产生的专业术语的个数:
感谢各位的阅读,以上就是“怎么使用java和python制作一个专业术语学习机”的内容了,经过本文的学习后,相信大家对怎么使用java和python制作一个专业术语学习机这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!