- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) >
- 如何使用java實(shí)現背單詞程序
這篇文章給大家分享的是有關(guān)如何使用java實(shí)現背單詞程序的內容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
具體內容如下
功能要求:可以讀入一個(gè)單詞表文本文件, 能夠將背錯的單詞重復記憶,直到全記住。
package java課程設計;import java.io.*;import java.util.*;public class word14T { public static void main(String[] args) { // TODO Auto-generated method stub File file=new File("word.txt"); //File file1=new File("wrong.txt"); TestWord test=new TestWord(); test.setFile(file);//類(lèi)調用setfile方法 test.setStopTime(5);//設置中間的暫停時(shí)間 test.startTest(); }}class TestWord{ File file; int stopTime; public void setFile(File f) { file=f; } public void setStopTime(int t) { stopTime=t; } public void startTest() { Scanner sc=null; Scanner read=new Scanner(System.in); try { sc=new Scanner(file); while(sc.hasNext()) { String word=sc.next(); System.out.println(word);//顯示要背的單詞 System.out.println("給"+stopTime+"秒背單詞的時(shí)間"); Thread.sleep(stopTime*1000);//使程序休眠一段時(shí)間來(lái)背誦單詞 System.out.println("\r"); for(int i=1;i<=50;i++) { System.out.println("*"); }//將前面的內容覆蓋 System.out.println("輸入曾經(jīng)顯示的單詞"); String input=read.nextLine();//將單詞讀入input中 if(input.equals(word)) { System.out.println("單詞正確");//匹配兩個(gè)單詞是否相同 } else { while(true)//將背錯的程序放在死循環(huán)中,如果正確則跳出 { System.out.println("單詞背錯了,繼續背該單詞"); System.out.println(word); FileWriter intwo=new FileWriter("wrong.txt"); BufferedWriter tofile=new BufferedWriter(intwo); BufferedWriter out=new BufferedWriter(tofile); out.write(word); System.out.println("給"+stopTime+"秒背單詞的時(shí)間"); Thread.sleep(stopTime*1000); System.out.println("\r"); for(int i=1;i<=50;i++) { System.out.println("*"); } System.out.println("輸入曾經(jīng)顯示的單詞"); input=read.nextLine(); if(input.equals(word)) { System.out.println("單詞正確"); break; } } } } } catch(Exception exp) { System.out.println(exp); } }}
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站