用java程序实现记单词_java实现背单词程序
本文實(shí)例為大家分享了java實(shí)現(xiàn)背單詞程序的具體代碼,供大家參考,具體內(nèi)容如下
山東科技大學(xué)濟(jì)南校區(qū)程序設(shè)計
功能要求:可以讀入一個單詞表文本文件, 能夠?qū)⒈冲e的單詞重復(fù)記憶,直到全記住。
package java課程設(shè)計;
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);//類調(diào)用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+"秒背單詞的時間");
Thread.sleep(stopTime*1000);//使程序休眠一段時間來背誦單詞
System.out.println("\r");
for(int i=1;i<=50;i++)
{
System.out.println("*");
}//將前面的內(nèi)容覆蓋
System.out.println("輸入曾經(jīng)顯示的單詞");
String input=read.nextLine();//將單詞讀入input中
if(input.equals(word))
{
System.out.println("單詞正確");//匹配兩個單詞是否相同
}
else
{
while(true)//將背錯的程序放在死循環(huán)中,如果正確則跳出
{ System.out.println("單詞背錯了,繼續(xù)背該單詞");
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+"秒背單詞的時間");
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);
}
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
時間: 2019-07-28
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的用java程序实现记单词_java实现背单词程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java反射sethaha_Java反射
- 下一篇: java consumer 使用_jav