這篇文章主要講解了“怎么使用java和python制作一個專業(yè)術(shù)語學習機”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么使用java和python制作一個專業(yè)術(shù)語學習機”吧!
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、成都做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、貴港ssl等。為上千余家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學管理、有技術(shù)的貴港網(wǎng)站制作公司
首先,我們需要一些專業(yè)名詞,制成詞典,從專業(yè)名詞中選出一些組合起來生成專業(yè)術(shù)語。
我決定從詞典里選擇4個組成專業(yè)術(shù)語,于是我做了4個詞典。容量雖然不夠大,但是當個玩具玩一玩還是夠的。
下面是我的專業(yè)名詞詞典:
String[] word1 = {"可用的","禁用","127%","平衡","轉(zhuǎn)移","4/3","2/7","78%","通用","限定"}; String[] word2 = {"RNA","DNA","串行設(shè)備","細胞","大容量","原蟲","分離"}; String[] word3 = {"總線","病毒","編譯","計算機","計算機病毒","移動","量產(chǎn)工具","培養(yǎng)皿","形態(tài)"}; String[] word4 = {"控制面板","作用器","日志","控制器","面板","用戶","存儲","管理員","域","尺","計數(shù)器"};
你可以在詞典里加入你自己的專業(yè)名詞。
接下來,我們需要隨機數(shù),以此從詞典中選出詞語。這里用到random方法:
int n1 = (int) (Math.random() * 10); //有一定經(jīng)驗者應(yīng)該都看懂了吧 int n2 = (int) (Math.random() * 7); int n3 = (int) (Math.random() * 9); int n4 = (int) (Math.random() * 11);
接下來,把名詞組合起來輸出:
System.out.print("\n您生成的專業(yè)術(shù)語是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n");
這時,我想批量生成專業(yè)術(shù)語怎么辦呢?
獲取用戶輸入,需要多少個專業(yè)術(shù)語:
System.out.print("請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):");Scanner sc = new Scanner(System.in);
轉(zhuǎn)化為int型:
int numbersc = sc.nextInt();
用計數(shù)器看看有沒有輸出完所需的專業(yè)術(shù)語:
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) + "個專業(yè)術(shù)語是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n"); number = number + 1; }
不斷循環(huán)地運行:
while(true) { System.out.print("請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):"); 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) + "個專業(yè)術(shù)語是:\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%","平衡","轉(zhuǎn)移","4/3","2/7","78%","通用","限定"}; String[] word2 = {"RNA","DNA","串行設(shè)備","細胞","大容量","原蟲","分離"}; String[] word3 = {"總線","病毒","編譯","計算機","計算機病毒","移動","量產(chǎn)工具","培養(yǎng)皿","形態(tài)"}; String[] word4 = {"控制面板","作用器","日志","控制器","面板","用戶","存儲","管理員","域","尺","計數(shù)器"}; while(true) { int number = 0; System.out.print("請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):"); 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) + "個專業(yè)術(shù)語是:\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%","平衡","轉(zhuǎn)移","4/3","2/7","78%","通用","限定"]; word2 = ["RNA","DNA","串行設(shè)備","細胞","大容量","原蟲","分離"]; word3 = ["總線","病毒","編譯","計算機","計算機病毒","移動","量產(chǎn)工具","培養(yǎng)皿","形態(tài)"]; word4 = ["控制面板","作用器","日志","控制器","面板","用戶","存儲","管理員","域","尺","計數(shù)器"]; while True: number = 0 numbersc = input("請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):") 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 + "個專業(yè)術(shù)語是:\n" + word1[n1] + word2[n2] + word3[n3] + word4[n4] + "\n") number += 1;
趕快拿上代碼,去到你的家人、朋友面前炫耀吧!
此處,給出一次運行結(jié)果(每次運行結(jié)果都不一樣?。?/p>
請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):5您生成的第1個專業(yè)術(shù)語是:通用細胞計算機病毒控制器 您生成的第2個專業(yè)術(shù)語是:平衡原蟲移動域 您生成的第3個專業(yè)術(shù)語是:2/7分離總線作用器 您生成的第4個專業(yè)術(shù)語是:平衡細胞量產(chǎn)工具尺 您生成的第5個專業(yè)術(shù)語是:通用大容量編譯管理員 請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù)(:
趕快拿上代碼,去到你的家人、朋友面前炫耀吧!
此處,給出一次運行結(jié)果(每次運行結(jié)果都不一樣!):
請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):5您生成的第1個專業(yè)術(shù)語是:通用細胞計算機病毒控制器 您生成的第2個專業(yè)術(shù)語是:平衡原蟲移動域 您生成的第3個專業(yè)術(shù)語是:2/7分離總線作用器 您生成的第4個專業(yè)術(shù)語是:平衡細胞量產(chǎn)工具尺 您生成的第5個專業(yè)術(shù)語是:通用大容量編譯管理員 請輸入要產(chǎn)生的專業(yè)術(shù)語的個數(shù):
感謝各位的閱讀,以上就是“怎么使用java和python制作一個專業(yè)術(shù)語學習機”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對怎么使用java和python制作一個專業(yè)術(shù)語學習機這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!