收藏 分享(赏)

day23作业答案.txt

上传人:a****2 文档编号:3482167 上传时间:2024-05-09 格式:TXT 页数:5 大小:5.16KB
下载 相关 举报
day23作业答案.txt_第1页
第1页 / 共5页
day23作业答案.txt_第2页
第2页 / 共5页
day23作业答案.txt_第3页
第3页 / 共5页
day23作业答案.txt_第4页
第4页 / 共5页
day23作业答案.txt_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、1!apublic class SubStringDemo public static void main(String args) / String str = hanbasdnbafllgnbahjnbakqqqqlnbaxnbai;String regex = nba;/ 1int count = getCount1(str, regex);/ 2int count2 = getCount2(str, regex);System.out.println(count);System.out.println(count2);/* * 2 */private static int getCou

2、nt2(String str, String regex) / int count = 0;/ int index = 0;/ 󣬿while (index = str.indexOf(regex, index) != -1) / +index = index + regex.length();/ +count+;return count;/* * 1 * int * 󴮺 * */public static int getCount1(String maxString, String minString) / int count = 0;/ int index

3、= 0;/ -1while (index = maxString.indexOf(minString) != -1) / +count+;/ ,maxString = maxString.substring(index + minString.length();return count;babbbbbccccdddeea(1)b(5)c(4)d(3)e(2)public class Test5 public static void main(String args) throws IOException / 1,String s = abbbbbccccdddee;/ 2,char arr =

4、 s.toCharArray();/ 3,洢TreeMap map = new TreeMap();/ 4,洢for (char c : arr) / 5,洢,1洢,1洢if (!map.containsKey(c) / map.put(c, 1); else map.put(c, map.get(c) + 1);/ 6,StringBuilder sb = new StringBuilder();for (Character key : map.keySet() / hm.keySet()sb.append(key + ( + map.get(key) + );/ System.out.pr

5、intln(sb);/ BufferedWriter bw = new BufferedWriter(new FileWriter(result.txt);bw.write(sb.toString();bw.close();3.javapublic class Test6 public static void main(String args) throws IOException File src = new File(D:src); / File dest = new File(D:dest); / if (src.equals(dest) System.out.println(); el

6、se copy(src, dest);/* * () 1,void 2,File src,File dest */public static void copy(File src, File dest) throws IOException / 1,洢FileFile subFiles = src.listFiles();/ 2,for (File subFile : subFiles) / 3,.javaioif (subFile.isFile() / .javaif (subFile.getName().endsWith(.java) BufferedInputStream bis = n

7、ew BufferedInputStream(new FileInputStream(subFile);/ File fff = new File(dest, subFile.getName(); / / + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fff);int b;while (b = bis.read() != -1) bos.write(b);bis.close();bos.close();/ 4, else copy(subFile, dest);2:(1)2()(2)354a:5b:532c:3d:523e:5f:5354(3)8()2()a:3.棬b:3档32

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教育教学 > 知识点总结

copyright@ 2008-2023 wnwk.com网站版权所有

经营许可证编号:浙ICP备2024059924号-2