首页 > 其他分享 >上课总结

上课总结

时间:2023-03-06 18:36:02浏览次数:27  
标签:总结 上课 String System 单词 yao words new

最长的相连英语单词串为:  apple - elephant – tree,  输出到文件里面,是这样的:

              Apple

              Elephant

              Tree

 

追加:判断文件不存在,文件无单词,文件一个单词,文件中无关联的(文件一个单词是其特殊情况)

在文本input.txt中取出单词,在outout.txt显示最长的相连英语单词串

任务分解:先行判断文件是否存在

不存在->显示错误

存在->取出单词存于内存中->判断单词数是否为一个

一个->显示错误

不是一个->判断相连英语单词(持续)(有一个判断是否重复的代码判断)->导出最长的相连英语单词串

我的所有错误在控制台的输出都注释掉了,改成在文本里显示

 

public class ClassTest {
public static void main(String[] args) throws IOException {

String filename = "D:/Coldplay.txt";
File a=new File(filename);

File file = new File("D://output.txt");
long startTime = System.currentTimeMillis();
//judeFileExists(a);
if (judeFileExists(a)) {
check(filename);
} else {
try {

FileWriter fw = new FileWriter(file);
fw.write("无此文件");
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis(); //获取结束时间
System.out.println("程序运行时间:" + (endTime - startTime) + "ms");
}

public static void check(String s) throws IOException {

BufferedReader br = new BufferedReader(new FileReader(s));
StringBuffer sb = new StringBuffer();
String text = null;
while ((text = br.readLine()) != null) {
sb.append(text);// 将读取出的字符追加到stringbuffer中
}
br.close(); // 关闭读入流
String str = sb.toString().toLowerCase(); // 将stringBuffer转为字符并转换为小写

String[] words = str.split("[^(a-zA-Z)]+"); // 非单词的字符来分割,得到所有单词

StringBuffer yao = new StringBuffer();
String b1 = words[0];
System.out.println(b1);
yao.append(b1);
yao.append(" ");

if (b1.equals("")) {
System.out.println("文件为空");
yao.append("文件为空");
} else {
if (words.length == 1) {
System.out.println("只有一个单词");
}

String end = b1.substring(b1.length() - 1, b1.length());
// System.out.println(end);
for (int i = 1; i < words.length; i++) {

String start = words[i].substring(0, 1);
if (end.equals(start)) {
if (ju(yao, words[i])) {
} else {
end = words[i].substring(words[i].length() - 1, words[i].length());
yao.append(words[i]);
yao.append(" ");
}

}
}

if (yao.toString().equals(words[0] + " ")) {
yao.append("无互联语句");
System.out.println("无互联词");
}
}


// for( String a:words)
// {
// System.out.println(a);
// }
// System.out.println(yao.toString());
File file = new File("D://output.txt");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

try {

FileWriter fw = new FileWriter(file);
fw.write(yao.toString());
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}


}

public static boolean ju(StringBuffer yao, String word) {
String a = yao.toString();
boolean flag = false;
String[] words = a.split("[^(a-zA-Z)]+"); // 非单词的字符来分割,得到所有单词
for (int i = 0; i < words.length; i++) {
if (word.equals(words[i])) {
flag = true;
}
}
return flag;
}

标签:总结,上课,String,System,单词,yao,words,new
From: https://www.cnblogs.com/yuncannotjava/p/17184913.html

相关文章

  • 3月06日课后总结
    3/06课后总结异常捕获补充try:print(ekaskl) #不会执行exceptExceptionase:print(e) #name'ekaskl'isnotdefinedelse:print('没得问题') #els......
  • Lodash中is系方法总结
    前言工作中经常会遇见变量容错处理的应用场景,而Lodash提供了很多空值判断和类型判断方法,现在挑选出常用的几个方法来进行分析,进而学习一下优秀的编码思路。isEmpty()......
  • 高德Go生态的服务稳定性建设|性能优化的实战总结
    高德Go生态的服务稳定性建设|性能优化的实战总结https://mp.weixin.qq.com/s/UHaCLhiIyLYVrba-nEUONA高德Go生态的服务稳定性建设|性能优化的实战总结原创 阳迪、联想、......
  • JS中创建对象与继承的方法总结
    js中对象的定义与其它面向对象语言不同,它的对象被描述为:一组无序属性的集合,其属性可以包含基本类型值、对象或者函数。而其它面向对象语言中的对象,通常指代可以通过类创建......
  • QDir类及其用法总结
    简介QDir类提供了访问系统目录结构及其内容的与平台无关的方式。头文件:#include<QDir>QDir类用来操作路径名及底层文件系统,获取关于目录路径及文件的相关信息,也......
  • SQL Server数据库的高性能优化经验总结二
    本文主要向大家介绍的是正确优化SQLServer数据库的经验总结,其中包括在对其进行优化的实际操作中值得大家注意的地方描述,以及对SQL语句进行优化的最基本原则,以下就是文章的......
  • SQL Server数据库优化大总结一
    SQL优化大总结:1.对查询进行优化,要尽量避免全表扫描,首先应考虑在where及orderby涉及的列上建立索引。2.应尽量避免在where子句中对字段进行null值判断,否则将导致引......
  • 3.5每日总结
     今天学习了TableLayout(表格布局)。android:collapseColumns:设置需要被隐藏的列的序号android:shrinkColumns:设置允许被收缩的列的列序号android:stretchColumns:设置......
  • odoo context上下文用法总结
    环境odoo-14.0.post20221212.tarcontext用法总结获取上下文>>>self.env.context#返回字典数据,等价于self._context{'lang':'en_US','tz':'Europe/Brussels'}>......
  • gson总结
    1、文档地址​​​https://sites.google.com/site/gson/gson-user-guide​​​2、例子PrimitivesExamples(Serialization)Gsongson=newGson();gson.toJson(1);......