Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CountMostImport/CountMostImport.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
99 changes: 99 additions & 0 deletions CountMostImport/src/com/qunar/homework/CountMostImport.java
Original file line number Diff line number Diff line change
@@ -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<String> javaFiles = jf.getFileLists();

//统计类与次数键值对
Map<String,Integer> map = new HashMap<String,Integer>();


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<Map.Entry<String, Integer>> infoIds =
new ArrayList<>(map.entrySet());
Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> 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<infoIds.size())
{
Map.Entry<String, Integer> entry = infoIds.get(freqRank);
String className = entry.getKey();
System.out.println(className+" "+entry.getValue());

freqRank++;
}


}
}
53 changes: 53 additions & 0 deletions CountMostImport/src/com/qunar/homework/JavaFiles.java
Original file line number Diff line number Diff line change
@@ -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<String> fileLists;


public JavaFiles() {
fileLists = new ArrayList<String>();
}

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<String> getFileLists() {
return fileLists;
}

public boolean isJavaFile(File file)
{
boolean result = false;
String str = file.getPath();
if(str.endsWith(".java"))
result = true;

return result;
}
}
26 changes: 26 additions & 0 deletions CountMostImport/src/com/qunar/homework/Test.java
Original file line number Diff line number Diff line change
@@ -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 {
}
12 changes: 12 additions & 0 deletions EffectiveLines/EffectiveLines.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.
Binary file not shown.
29 changes: 29 additions & 0 deletions EffectiveLines/src/Test.java
Original file line number Diff line number Diff line change
@@ -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<end){
System.out.println("No");
}
}
}

37 changes: 37 additions & 0 deletions EffectiveLines/src/com/qunar/homework/EffectiveLines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.qunar.homework;

import java.io.*;

/**
* Created by Jerry on 6/27/2016.
*/
public class EffectiveLines {
static int codeLines = 0;
public static void main(String[] args) {
File file = new File("src/Test.java");
computeLines(file);
System.out.println("EffectiveLines is "+codeLines);
}

public static void computeLines(File file)
{
BufferedReader bf = null;
try {
bf = new BufferedReader(new FileReader(file));
String line = "";
while((line=bf.readLine())!=null)
{
if(line.trim().equals(""))
continue;
else if(line.trim().startsWith("//")||line.trim().startsWith("/*"))
continue;
codeLines++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}

}
29 changes: 29 additions & 0 deletions ExchangeRate/ExchangeRate.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/Lib/jsoup-1.9.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/Lib/jxl.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
Binary file added ExchangeRate/ExchangeRate.xls
Binary file not shown.
Binary file added ExchangeRate/Lib/jsoup-1.9.2.jar
Binary file not shown.
Binary file added ExchangeRate/Lib/jxl.jar
Binary file not shown.
Binary file not shown.
Loading