forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from gabywong/master
3.5作业
- Loading branch information
Showing
19 changed files
with
974 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
group15/1513_121469918/HomeWork01/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/coding/ArrayList.java=GBK | ||
encoding//src/coding/BinaryTreeNode.java=GBK | ||
encoding//src/coding/Iterator.java=GBK | ||
encoding//src/coding/LinkedList.java=GBK | ||
encoding//src/coding/List.java=GBK | ||
encoding//src/coding/Queue.java=GBK | ||
encoding//src/coding/Stack.java=GBK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="lib" path="dom4j-1.6.1.jar"/> | ||
<classpathentry kind="lib" path="jaxen-1.1-beta-6.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>HomeWork20170305</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> |
9 changes: 9 additions & 0 deletions
9
group15/1513_121469918/HomeWork20170305/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/com/coderising/array/ArrayUtil.java=UTF-8 | ||
encoding//src/com/coding/basic/ArrayList.java=GBK | ||
encoding//src/com/coding/basic/BinaryTreeNode.java=GBK | ||
encoding//src/com/coding/basic/Iterator.java=GBK | ||
encoding//src/com/coding/basic/LinkedList.java=GBK | ||
encoding//src/com/coding/basic/List.java=GBK | ||
encoding//src/com/coding/basic/Queue.java=GBK | ||
encoding//src/com/coding/basic/Stack.java=GBK |
11 changes: 11 additions & 0 deletions
11
group15/1513_121469918/HomeWork20170305/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
11 changes: 11 additions & 0 deletions
11
group15/1513_121469918/HomeWork20170305/bin/com/coderising/litestruts/struts.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<struts> | ||
<action name="login" class="com.coderising.litestruts.LoginAction"> | ||
<result name="success">/jsp/homepage.jsp</result> | ||
<result name="fail">/jsp/showLogin.jsp</result> | ||
</action> | ||
<action name="logout" class="com.coderising.action.LogoutAction"> | ||
<result name= "success">/jsp/welcome.jsp</result> | ||
<result name= "error">/jsp/error.jsp</result> | ||
</action> | ||
</struts> |
244 changes: 244 additions & 0 deletions
244
group15/1513_121469918/HomeWork20170305/src/com/coderising/array/ArrayUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
package com.coderising.array; | ||
|
||
import java.util.Arrays; | ||
import java.util.TreeSet; | ||
|
||
import com.coding.basic.ArrayList; | ||
import com.coding.basic.Iterator; | ||
|
||
public class 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 void reverseArray(int[] origin) { | ||
int len = origin.length; | ||
for (int i = 0; i < len / 2; i++) { | ||
int temp = origin[i]; | ||
origin[i] = origin[len - 1 - i]; | ||
origin[len - 1 - i] = 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 int[] removeZero(int[] oldArray) { | ||
int count = 0; | ||
|
||
// 创建一个临时数组装没有零的旧数组 | ||
int[] temp = new int[oldArray.length - count]; | ||
for (int i = 0; i < oldArray.length; i++) { | ||
if (oldArray[i] == 0) { | ||
// 如果值为0,统计、跳过不加入新数组 | ||
count++; | ||
continue; | ||
} else { | ||
temp[i - count] = oldArray[i]; | ||
} | ||
} | ||
// 定义返回数组的长度 | ||
int len = oldArray.length - count; | ||
int[] resultArray = new int[len]; | ||
System.arraycopy(temp, 0, resultArray, 0, len); | ||
return resultArray; | ||
} | ||
|
||
/** | ||
* 给定两个已经排序好的整形数组, 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 int[] merge(int[] array1, int[] array2) { | ||
int[] result = array1; | ||
// 去除重复元素 | ||
for (int i = 0; i < array2.length; i++) { | ||
boolean sameVal = false; | ||
for (int j = 0; j < array1.length; j++) { | ||
if (array1[j] == array2[i]) { | ||
sameVal = true; | ||
break; | ||
} | ||
} | ||
if(sameVal == false){ | ||
result = grow(result, 1); | ||
result[result.length-1] = array2[i]; | ||
} | ||
} | ||
//冒泡排序 | ||
for (int i = 0; i < result.length-1; i++) { | ||
for (int j = i+1; j < result.length; j++) { | ||
if(result[i]>result[j]){ | ||
int temp = result[i]; | ||
result[i] = result[j]; | ||
result[j] =temp; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size | ||
* 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为 | ||
* [2,3,6,0,0,0] | ||
* | ||
* @param oldArray | ||
* @param size | ||
* @return | ||
*/ | ||
public int[] grow(int[] oldArray, int size) { | ||
int[] resultArray = new int[oldArray.length + size]; | ||
System.arraycopy(oldArray, 0, resultArray, 0, oldArray.length); | ||
return resultArray; | ||
} | ||
|
||
/** | ||
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 例如, max = 15 , | ||
* 则返回的数组应该为 [1,1,2,3,5,8,13] max = 1, 则返回空数组 [] | ||
* | ||
* @param max | ||
* @return | ||
*/ | ||
public int[] fibonacci(int max) { | ||
if (max <= 1) { | ||
return new int[0]; | ||
} else { | ||
int[] temp = new int[max]; | ||
temp[0] = 1; | ||
temp[1] = 1; | ||
// 定义返回数组的长度变量 | ||
int len = 2; | ||
for (int i = 2; i < max; i++) { | ||
int last = temp[i - 1] + temp[i - 2]; | ||
if (last >= max) { | ||
break; | ||
} else { | ||
temp[i] = last; | ||
len = i + 1; | ||
} | ||
} | ||
return Arrays.copyOf(temp, len); | ||
} | ||
} | ||
|
||
/** | ||
* 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] | ||
* | ||
* @param max | ||
* @return | ||
*/ | ||
public int[] getPrimes(int max) { | ||
|
||
if (max <= 1) { | ||
return new int[0]; | ||
} else { | ||
// 创建临时数组 | ||
int[] temp = new int[max]; | ||
int count = 0; | ||
// 从零开始遍历到max,如果有是素数就加入临时数组。 | ||
for (int i = 0; i < max; i++) { | ||
if (isPrimes(i)) { | ||
temp[i - count] = i; | ||
} else { | ||
count++; | ||
} | ||
} | ||
// max -1 -count是最后一个元素索引 | ||
int len = max - count; | ||
int[] resultArray = Arrays.copyOf(temp, len); | ||
return resultArray; | ||
} | ||
} | ||
|
||
boolean isPrimes(int x) { | ||
if (x <= 1) { | ||
return false; | ||
} else { | ||
for (int i = 2; i < x; i++) { | ||
if (x % i == 0) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 | ||
* | ||
* @param max | ||
* @return | ||
*/ | ||
public int[] getPerfectNumbers(int max) { | ||
if (max < 1) { | ||
return new int[0]; | ||
} else { | ||
ArrayList array = new ArrayList(); | ||
for (int i = 1; i <= max; i++) { | ||
if (isPerfectNumber(i)) { | ||
array.add(i); | ||
} | ||
} | ||
int[] result = new int[array.size()]; | ||
Iterator it = array.iterator(); | ||
int index = 0; | ||
while (it.hasNext()) { | ||
result[index] = ((Integer) it.next()).intValue(); | ||
index++; | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
boolean isPerfectNumber(int x) { | ||
if (x < 1) { | ||
return false; | ||
} else { | ||
int count = 0; | ||
for (int i = 1; i < x; i++) { | ||
if (x % i == 0) { | ||
count += i; | ||
} | ||
} | ||
if (x == count) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9" | ||
* | ||
* @param array | ||
* @param s | ||
* @return | ||
*/ | ||
public String join(int[] array, String seperator) { | ||
StringBuffer sb = new StringBuffer(); | ||
for (int i = 0; i < array.length; i++) { | ||
if(i == array.length-1){ | ||
sb.append(String.valueOf(array[i])); | ||
break; | ||
} | ||
sb.append(String.valueOf(array[i])+seperator); | ||
} | ||
String result = sb.toString(); | ||
return result; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
group15/1513_121469918/HomeWork20170305/src/com/coderising/litestruts/LoginAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.coderising.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; | ||
} | ||
} |
Oops, something went wrong.