温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用java实现背单词程序

发布时间:2021-09-26 18:19:03 来源:亿速云 阅读:151 作者:小新 栏目:编程语言

这篇文章给大家分享的是有关如何使用java实现背单词程序的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体内容如下

功能要求:可以读入一个单词表文本文件, 能够将背错的单词重复记忆,直到全记住。

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);//类调用setfile方法  test.setStopTime(5);//设置中间的暂停时间  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("*");    }//将前面的内容覆盖    System.out.println("输入曾经显示的单词");    String input=read.nextLine();//将单词读入input中    if(input.equals(word))    {     System.out.println("单词正确");//匹配两个单词是否相同    }    else    {     while(true)//将背错的程序放在死循环中,如果正确则跳出     { 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+"秒背单词的时间");     Thread.sleep(stopTime*1000);     System.out.println("\r");     for(int i=1;i<=50;i++)     {      System.out.println("*");     }     System.out.println("输入曾经显示的单词");     input=read.nextLine();     if(input.equals(word))     {      System.out.println("单词正确");      break;     }    }    }   }  }  catch(Exception exp)  {   System.out.println(exp);  } }}

感谢各位的阅读!关于“如何使用java实现背单词程序”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI