您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么使用java和python制作一個專業術語學習機”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么使用java和python制作一個專業術語學習機”吧!
首先,我們需要一些專業名詞,制成詞典,從專業名詞中選出一些組合起來生成專業術語。
我決定從詞典里選擇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制作一個專業術語學習機這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。