Skip to content

Commit

Permalink
Merge pull request #2 from heyucool/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
MicheyGarcia authored Mar 10, 2017
2 parents 8f8b136 + 005b56a commit 309a852
Show file tree
Hide file tree
Showing 2,094 changed files with 111,041 additions and 13,191 deletions.
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@

*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

#ide config
.metadata
.recommenders
.idea/
*.iml
rebel.*
.rebel.*

target
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>coding2017</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
8 changes: 8 additions & 0 deletions group01/1298552064/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="src/dom4j-1.6.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
File renamed without changes.
17 changes: 17 additions & 0 deletions group01/1298552064/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>1298552064Learning</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
2 changes: 1 addition & 1 deletion group01/1298552064/src/week01/basic/MyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Object removeLast() {
Node p = head;
for (int i = 0; i < size; i++) {
if (p.next.next == null) {
removeObject = p.next;
removeObject = p.next.data;
p.next = null;
break;
} else {
Expand Down
245 changes: 245 additions & 0 deletions group01/1298552064/src/week02/array/ArrayUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
package week02.array;

import java.util.Arrays;

public class ArrayUtil {

// 工具类,不予许创建实例
private ArrayUtil() {
}

/**
* 给定一个整形数组a , 对该数组的值进行置换 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] 如果 a =
* [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
*
* @param origin
* @return
*/
public static void reverseArray(int[] origin) {
if (origin != null && origin.length > 0) {
int temp = 0;

// 数组首尾元素置换
for (int i = 0; i < origin.length / 2; i++) {
temp = origin[i];
origin[i] = origin[origin.length - i - 1];
origin[origin.length - i - 1] = temp;
}
}
}

/**
* 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
* 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: {1,3,4,5,6,6,5,4,7,6,7,5}
*
* @param oldArray
* @return
*/

public static int[] removeZero(int[] oldArray) {
int[] newArray = null;
if (oldArray != null) {
newArray = new int[oldArray.length];
int size = 0;
for (int i = 0; i < oldArray.length; i++) {
if (oldArray[i] != 0) {
newArray[size] = oldArray[i];
size++;
}
}
newArray = Arrays.copyOf(newArray, size);
}
return newArray;
}

/**
* 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 例如 a1 =
* [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
*
* @param array1
* @param array2
* @return
*/

public static int[] merge(int[] array1, int[] array2) {
int[] newArray = null;
if (array1 != null && array2 != null) {
int size = 0;

// index1、index2表示array1和array2数组的比较索引
int index1 = 0, index2 = 0;
newArray = new int[array1.length + array2.length];

while (index1 < array1.length && index2 < array2.length) {
if (array1[index1] == array2[index2]) {
newArray[size++] = array1[index1];
index1++;
index2++;
} else if (array1[index1] < array2[index2]) {
// 数组array1去重
if (size > 0 && array1[index1] == newArray[size - 1]) {
size--;
}
newArray[size++] = array1[index1];
index1++;
} else {
// 数组array2去重
if (size > 0 && array2[index2] == newArray[size - 1]) {
size--;
}
newArray[size++] = array2[index2];
index2++;
}
}

// 将数组array1剩下的元素放入
while (index1 < array1.length) {
newArray[size++] = array1[index1++];
}

// 将数组array2剩下的元素放入
while (index2 < array2.length) {
newArray[size++] = array2[index2++];
}

// 合并后有序数组
newArray = Arrays.copyOf(newArray, size);
}
return newArray;
}

/**
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
* 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
* [2,3,6,0,0,0]
*
* @param oldArray
* @param size
* @return
*/
public static int[] grow(int[] oldArray, int size) {
int[] newArray = null;
if (oldArray != null) {
newArray = new int[oldArray.length + size];
for (int i = 0; i < oldArray.length; i++) {
newArray[i] = oldArray[i];
}
}
return newArray;
}

/**
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 例如, max = 15 ,
* 则返回的数组应该为 [1,1,2,3,5,8,13] max = 1, 则返回空数组 []
*
* @param max
* @return
*/
public static int[] fibonacci(int max) {

// 计算方法:f(n) = f(n-1) + f(n-2) 采用数组计算
int[] result = null;
if (max <= 1) {
result = new int[] {};
} else {
int i = 2;
result = new int[max];
result[0] = result[1] = 1;
for (; i < max; i++) {
if (result[i - 1] + result[i - 2] < max) {
result[i] = result[i - 1] + result[i - 2];
} else {
break;
}
}
result = Arrays.copyOf(result, i);
}
return result;
}

/**
* 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
*
* @param max
* @return
*/
public static int[] getPrimes(int max) {
int[] newArray = new int[] {};
if (max > 2) {
newArray = new int[max];
int size = 0, j = 0;
for (int i = 2; i < max; i++) {
for (j = 2; j < i / 2 + 1; j++) {
if (i % j == 0) {
break;
}
}

if (j == i / 2 + 1) {
newArray[size++] = i;
}
}
newArray = Arrays.copyOf(newArray, size);
}
return newArray;
}

/**
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
*
* @param max
* @return
*/
public static int[] getPerfectNumbers(int max) {
int[] newArray = new int[] {};
if (max > 0) {
newArray = new int[max];
int size = 0, sum = 0;
for (int i = 1; i < max; i++) {
sum = 0;
for (int j = 1; j < i / 2 + 1; j++) {
if (i % j == 0) {
sum += j;
}
}
if (i == sum) {
newArray[size++] = i;
}
}
newArray = Arrays.copyOf(newArray, size);
}
return newArray;
}

/**
* 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9"
*
* @param array
* @param seperator
* @return
*/
public static String join(int[] array, String seperator) {
String joinResult = null;
if (array != null) {
joinResult = "";
for (int i = 0; i < array.length; i++) {
joinResult += array[i] + seperator;
}
joinResult = joinResult.equals("") ? "" : joinResult.substring(0, joinResult.length() - 1);
}
return joinResult;
}

public static void main(String[] args) {
int[] a = new ArrayUtil().getPerfectNumbers(1000);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}

// [2,3,5,7,11,13,17,19]
a = new ArrayUtil().getPrimes(20);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
42 changes: 42 additions & 0 deletions group01/1298552064/src/week02/litestruts/LoginAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package week02.litestruts;

/**
* 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
*
* @author liuxin
*
*/
public class LoginAction {
private String name;
private String password;
private String message;

public String getName() {
return name;
}

public String getPassword() {
return password;
}

public String execute() {
if ("test".equals(name) && "1234".equals(password)) {
this.message = "login successful";
return "success";
}
this.message = "login failed,please check your user/pwd";
return "fail";
}

public void setName(String name) {
this.name = name;
}

public void setPassword(String password) {
this.password = password;
}

public String getMessage() {
return this.message;
}
}
Loading

0 comments on commit 309a852

Please sign in to comment.