diff --git a/CountMostImport/CountMostImport.iml b/CountMostImport/CountMostImport.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/CountMostImport/CountMostImport.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/CountMostImport/out/production/CountMostImport/com/qunar/homework/CountMostImport$1.class b/CountMostImport/out/production/CountMostImport/com/qunar/homework/CountMostImport$1.class new file mode 100644 index 0000000..346ed49 Binary files /dev/null and b/CountMostImport/out/production/CountMostImport/com/qunar/homework/CountMostImport$1.class differ diff --git a/CountMostImport/out/production/CountMostImport/com/qunar/homework/CountMostImport.class b/CountMostImport/out/production/CountMostImport/com/qunar/homework/CountMostImport.class new file mode 100644 index 0000000..844ba59 Binary files /dev/null and b/CountMostImport/out/production/CountMostImport/com/qunar/homework/CountMostImport.class differ diff --git a/CountMostImport/out/production/CountMostImport/com/qunar/homework/JavaFiles.class b/CountMostImport/out/production/CountMostImport/com/qunar/homework/JavaFiles.class new file mode 100644 index 0000000..24bd762 Binary files /dev/null and b/CountMostImport/out/production/CountMostImport/com/qunar/homework/JavaFiles.class differ diff --git a/CountMostImport/out/production/CountMostImport/com/qunar/homework/Test.class b/CountMostImport/out/production/CountMostImport/com/qunar/homework/Test.class new file mode 100644 index 0000000..6491f68 Binary files /dev/null and b/CountMostImport/out/production/CountMostImport/com/qunar/homework/Test.class differ diff --git a/CountMostImport/src/com/qunar/homework/CountMostImport.java b/CountMostImport/src/com/qunar/homework/CountMostImport.java new file mode 100644 index 0000000..f646ae1 --- /dev/null +++ b/CountMostImport/src/com/qunar/homework/CountMostImport.java @@ -0,0 +1,99 @@ +package com.qunar.homework; + +import java.io.*; +import java.util.*; + + +//以下import类作为测试用 +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Executable; +import java.lang.reflect.Executable; +import java.lang.reflect.Executable; +import java.lang.Integer; +import java.lang.Integer; +import java.io.BufferedReader; +import java.io.Reader; +import java.io.ByteArrayInputStream; +import java.io.CharArrayReader; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceConfigurationError; +import java.util.Set; + +/** + * Created by Jerry on 6/26/2016. + */ +public class CountMostImport { + + public static void main(String[] args) { + + //获取目录下的所有Java文件 + String add = "src"; + File file = new File(add); + JavaFiles jf = new JavaFiles(); + jf.getFileLists(file); + List javaFiles = jf.getFileLists(); + + //统计类与次数键值对 + Map map = new HashMap(); + + + BufferedReader bf=null; + for (String str : javaFiles) { + // System.out.println("args = [" + str + "]"); + File javaFile = new File(str); + try { + bf = new BufferedReader(new FileReader(new File(str))); + } catch (FileNotFoundException e) { + System.out.println("读入文件错误..."); + } + + String line = null; + try { + while((line=bf.readLine())!=null) + { + if(line.trim().startsWith("import")&&!(line.endsWith("*;"))) + { + String [] split = line.trim().split(" "); + System.out.println("args = [" + split[1] + "]"); + String importClass = split[1].trim().substring(0,split[1].trim().length()-1); + Integer count = map.get(importClass); + map.put(importClass,count==null?1:count+1); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + //sort + List> infoIds = + new ArrayList<>(map.entrySet()); + Collections.sort(infoIds, new Comparator>() { + public int compare(Map.Entry o1, Map.Entry o2) { + int value = (o2.getValue()).compareTo(o1.getValue()); + if(value==0) //如果import次数相等则按类名字典序 + return (o1.getKey()).compareTo(o2.getKey()); + else + return value; + } + }); + + + //按次序输出 + int freqRank = 0; + while(freqRank<10&&freqRank entry = infoIds.get(freqRank); + String className = entry.getKey(); + System.out.println(className+" "+entry.getValue()); + + freqRank++; + } + + + } +} diff --git a/CountMostImport/src/com/qunar/homework/JavaFiles.java b/CountMostImport/src/com/qunar/homework/JavaFiles.java new file mode 100644 index 0000000..ce716a7 --- /dev/null +++ b/CountMostImport/src/com/qunar/homework/JavaFiles.java @@ -0,0 +1,53 @@ +package com.qunar.homework; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Jerry on 6/26/2016. + */ +public class JavaFiles { + private List fileLists; + + + public JavaFiles() { + fileLists = new ArrayList(); + } + + public void getFileLists(File file) + { + if(file==null) return; + File[] files = file.listFiles(); + if(files==null) + return; + for (File f:files) { + if(f.isDirectory()){ + getFileLists(f); + } + else + { + if(isJavaFile(f)) + { + fileLists.add(f.getPath()); + + + } + } + } + } + + public List getFileLists() { + return fileLists; + } + + public boolean isJavaFile(File file) + { + boolean result = false; + String str = file.getPath(); + if(str.endsWith(".java")) + result = true; + + return result; + } +} diff --git a/CountMostImport/src/com/qunar/homework/Test.java b/CountMostImport/src/com/qunar/homework/Test.java new file mode 100644 index 0000000..ed3cb19 --- /dev/null +++ b/CountMostImport/src/com/qunar/homework/Test.java @@ -0,0 +1,26 @@ +package com.qunar.homework; + +/** + * Created by Jerry on 6/26/2016. + */ + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Executable; +import java.lang.reflect.Executable; +import java.lang.reflect.Executable; +import java.lang.Integer; +import java.lang.Integer; +import java.io.BufferedReader; +import java.io.Reader; +import java.io.ByteArrayInputStream; +import java.io.CharArrayReader; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceConfigurationError; +import java.util.Set; + + + +public class Test { +} diff --git a/EffectiveLines/EffectiveLines.iml b/EffectiveLines/EffectiveLines.iml new file mode 100644 index 0000000..bcd2974 --- /dev/null +++ b/EffectiveLines/EffectiveLines.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/EffectiveLines/out/production/EffectiveLines/Test.class b/EffectiveLines/out/production/EffectiveLines/Test.class new file mode 100644 index 0000000..66cdaa4 Binary files /dev/null and b/EffectiveLines/out/production/EffectiveLines/Test.class differ diff --git a/EffectiveLines/out/production/EffectiveLines/com/qunar/homework/EffectiveLines.class b/EffectiveLines/out/production/EffectiveLines/com/qunar/homework/EffectiveLines.class new file mode 100644 index 0000000..8336564 Binary files /dev/null and b/EffectiveLines/out/production/EffectiveLines/com/qunar/homework/EffectiveLines.class differ diff --git a/EffectiveLines/src/Test.java b/EffectiveLines/src/Test.java new file mode 100644 index 0000000..c948dd6 --- /dev/null +++ b/EffectiveLines/src/Test.java @@ -0,0 +1,29 @@ +/* Created by Jerry on 6/22/2016.*/ + + +import java.util.Scanner; +/*Jerry*/ +public class Test { + //test + public static void main(String [] args){ + System.out.println("Ҫַ:"); + Scanner s = new Scanner(System.in); + String str = s.next(); + s.close(); + int start = 0; + int end = str.length()-1; + while(str.charAt(start)==str.charAt(end)){ + start ++; + end--; + if(start>end){ + System.out.println("Yes"); + break; + } + + } + if(start + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ExchangeRate/ExchangeRate.xls b/ExchangeRate/ExchangeRate.xls new file mode 100644 index 0000000..19a39ee Binary files /dev/null and b/ExchangeRate/ExchangeRate.xls differ diff --git a/ExchangeRate/Lib/jsoup-1.9.2.jar b/ExchangeRate/Lib/jsoup-1.9.2.jar new file mode 100644 index 0000000..720b761 Binary files /dev/null and b/ExchangeRate/Lib/jsoup-1.9.2.jar differ diff --git a/ExchangeRate/Lib/jxl.jar b/ExchangeRate/Lib/jxl.jar new file mode 100644 index 0000000..c68a0be Binary files /dev/null and b/ExchangeRate/Lib/jxl.jar differ diff --git a/ExchangeRate/out/production/ExchangeRate/com/qunar/homework/ExchangeRate.class b/ExchangeRate/out/production/ExchangeRate/com/qunar/homework/ExchangeRate.class new file mode 100644 index 0000000..16d0520 Binary files /dev/null and b/ExchangeRate/out/production/ExchangeRate/com/qunar/homework/ExchangeRate.class differ diff --git a/ExchangeRate/src/com/qunar/homework/ExchangeRate.java b/ExchangeRate/src/com/qunar/homework/ExchangeRate.java new file mode 100644 index 0000000..b6a2d09 --- /dev/null +++ b/ExchangeRate/src/com/qunar/homework/ExchangeRate.java @@ -0,0 +1,104 @@ +package com.qunar.homework; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; +import java.io.File; +import java.io.IOException; +import jxl.Workbook; +import jxl.write.*; + + +/** + * Created by TOSHIBA on 2016/6/14. + */ +public class ExchangeRate { + + public static void main(String[] args) { + //定义开始与结束的时间 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar cal = Calendar.getInstance(); + String endDay = sdf.format(cal.getTime()); + cal.add(cal.DATE, -30); + String startDay = sdf.format(cal.getTime()); + //链接数据 + Document doc = null; + try { + doc = Jsoup.connect("http://www.safe.gov.cn/AppStructured/view/project_RMBQuery.action").data("projectBean.startDate", startDay).data("projectBean.endDate", endDay).get(); + } catch (IOException e) { + e.printStackTrace(); + } + + + //创建Excel + WritableWorkbook wwb = null; + File file = new File("ExchangeRate.xls"); + if(file.exists()) //如果存在,则删除 + file.delete(); + + + try { + wwb = Workbook.createWorkbook(file); + } catch (IOException e) { + e.printStackTrace(); + } + WritableSheet ws=null; + ws = wwb.createSheet("近30天内人民币汇率中间价", 0); //创建sheet + + + //获取并写入Excel + Element table = doc.getElementsByClass("list").first(); + Elements titles = table.getElementsByClass("table_head"); + Elements data = table.getElementsByClass("first"); + int[] Num = {0, 1, 2, 4}; + int j = 0; + //向Excel写入数据 + for (int i = 0; i < 4; i++) { + j=0; + + //写入表头 + String title = titles.get(Num[i]).text(); + Label lbl = new Label(i, j, title); + try { + ws.addCell(lbl); + } catch (WriteException e) { + e.printStackTrace(); + } + j++; + + + //写入每天的汇率中间价 + for(int k = 0;k