forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c10cd4
commit 5aecbf2
Showing
6 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
group06/799237637/secondhomework/src/com/liteStructs/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,5 @@ | ||
package com.liteStructs; | ||
|
||
public class LoginAction { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
group06/799237637/secondhomework/src/com/liteStructs/Structs.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,5 @@ | ||
package com.liteStructs; | ||
|
||
public class Structs { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
group06/799237637/secondhomework/src/com/liteStructs/View.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,5 @@ | ||
package com.liteStructs; | ||
|
||
public class View { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
group06/799237637/secondhomework/src/com/liteStructs/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.liteStructs.action.LogoutAction"> | ||
<result name="success">/jsp/homepage.jsp</result> | ||
<result name="fail">/jsp/showLogin.jsp</result> | ||
</action> | ||
<action name="logout" class="com.liteStructs.action.LogoutAction"> | ||
<result name="success">/jsp/welcome.jsp</result> | ||
<result name="error">/jsp/error.jsp</result> | ||
</action> | ||
</struts> |
214 changes: 214 additions & 0 deletions
214
group06/799237637/secondhomework/src/secondhomework/MyArrayUtil.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,214 @@ | ||
package secondhomework; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/* | ||
* 实现ArrayUtil | ||
*/ | ||
@SuppressWarnings("all") | ||
public class MyArrayUtil { | ||
/** | ||
* 给定一个整形数组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 size =origin.length; | ||
|
||
for(int i=0;i<size/2;i++){ | ||
int temp=origin[i]; | ||
origin[i]=origin[size-1-i]; | ||
origin[size-1-i]=temp; | ||
} | ||
System.out.println(Arrays.toString(origin)); | ||
} | ||
|
||
/** | ||
* 现在有如下的一个数组: 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 void removeZero(int[] oldArray){ | ||
StringBuilder sb=new StringBuilder(); | ||
sb.append("["); | ||
for(int i=0;i<oldArray.length;i++){ | ||
if(oldArray[i]!=0){ | ||
sb.append(oldArray[i]); | ||
if(i<oldArray.length-1-1){ | ||
sb.append(","); | ||
} | ||
} | ||
} | ||
sb.append("]"); | ||
System.out.println(sb); | ||
} | ||
|
||
/** | ||
* 给定两个已经排序好的整形数组, 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 void merge(int[] array1, int[] array2){ | ||
ArrayList al = new ArrayList(); | ||
for(int i=0;i<array1.length;i++){ | ||
al.add(array1[i]); | ||
} | ||
|
||
for(int i=0;i<array2.length;i++){ | ||
if(!al.contains(array2[i])){ | ||
al.add(array2[i]); | ||
} | ||
} | ||
System.out.println(al); | ||
|
||
|
||
} | ||
|
||
/** | ||
* 把一个已经存满数据的数组 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 newLength = oldArray.length; | ||
int[] newArray=Arrays.copyOf(oldArray, newLength+size); | ||
|
||
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 int ifobonacci(int num){ | ||
if(num==1||num==2){ | ||
return 1; | ||
}else{ | ||
return ifobonacci(num-2)+ifobonacci(num-1); | ||
} | ||
} | ||
|
||
public void fibonacci(int max){ | ||
ArrayList al= new ArrayList(); | ||
for(int i=1;i<max;i++){ | ||
if(ifobonacci(i)<max){ | ||
al.add(ifobonacci(i)); | ||
} | ||
} | ||
System.out.println(Arrays.toString(al.toArray())); | ||
|
||
} | ||
/** | ||
* 返回小于给定最大值max的所有素数数组 | ||
* 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] | ||
* @param max | ||
* @return | ||
*/ | ||
|
||
public boolean isPrimes(int num){ | ||
boolean flag=true; | ||
if(num<2){ | ||
return false; | ||
}else{ | ||
for(int i=2;i<num;i++){ | ||
if(num%i==0){ | ||
flag=false; | ||
break; | ||
} | ||
} | ||
return flag; | ||
} | ||
|
||
|
||
} | ||
public void getPrimes(int max){ | ||
ArrayList al= new ArrayList(); | ||
for(int i=2;i<max;i++){ | ||
if(isPrimes(i)){ | ||
al.add(i); | ||
} | ||
} | ||
Object[] o=al.toArray(); | ||
System.out.println(Arrays.toString(o)); | ||
|
||
} | ||
|
||
/** | ||
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 | ||
* 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 | ||
* @param max | ||
* @return | ||
*/ | ||
public void getPerfectNumbers(int max){ | ||
|
||
ArrayList alist= new ArrayList(); | ||
for(int i=1;i<=max;i++){ | ||
int sum=0; | ||
for(int j=1;j<=i/2;j++){ | ||
if(i%j==0){ | ||
sum+=j; | ||
} | ||
} | ||
if(sum==i){ | ||
alist.add(i); | ||
} | ||
} | ||
System.out.println(alist); | ||
} | ||
|
||
/** | ||
* 用seperator 把数组 array给连接起来 | ||
* 例如array= [3,8,9], seperator = "-" | ||
* 则返回值为"3-8-9" | ||
* @param array | ||
* @param s | ||
* @return | ||
*/ | ||
public void join(int[] array, String seperator){ | ||
StringBuilder sb =new StringBuilder(); | ||
for(int i=0;i<array.length;i++){ | ||
sb.append(array[i]); | ||
if(i<array.length-1){ | ||
sb.append(seperator); | ||
} | ||
} | ||
System.out.println(sb.toString()); | ||
} | ||
|
||
|
||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
MyArrayUtil my= new MyArrayUtil(); | ||
int[] a={0,1,2,3,4,6,7,8,6,0,12,0,29,98,0,2}; | ||
// my.reverseArray(a); | ||
// my.removeZero(a); | ||
|
||
int[] array1={1,2,3}; | ||
int[] array2={3,4,5}; | ||
// my.merge(array1, array2); | ||
// my.getPrimes(20); | ||
my.getPerfectNumbers(30); | ||
my.join(array1, "-"); | ||
System.out.println(Arrays.toString(my.grow(array1, 3))); | ||
my.fibonacci(15); | ||
} | ||
|
||
} |
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 @@ | ||
http://blog.csdn.net/codingxiaozhupig/article/details/60349989 |