package com.shb.java; /** * 将数组中的0放到数组的后边,然后原来的非零数的顺序不改变 * @author BIN * */ public class Demo2{ public static void main(String[] args){ getArray(new int[]{1,0,0,5,0}); } public static int[] getArray(int[] array){ int cur = 0; for(int i=0;i<array.leng
package Code411;//求数组的最大值public class CodeArrayMax { public static void main(String[] args) { int array[]={5,15,30,20,100}; int max=array[0]; for (int i = 1; i < array.length; i++) { //若比max大,则换 if(array[i]>max){ max=array[i]; } } System.out.println
public class Test3 { public static void main(String[] args) { int[] grade = {87,88,89,98,78}; int m; for(int i = 0; i < 2; i++){ m = grade[i]; grade[i] = grade[5-i-1]; grade[5-i-1] = m; } for(int j =0; j < 5; j++){ System.out.println(grade[j]); } }
public static Integer getNumberThree(Integer[] intarray,Integer number){ int index = Math.abs(number-intarray[0]); int result = intarray[0]; for (int i : intarray) { int abs = Math.abs(number-i); if(abs <= index){ index = abs; result = i; } } return
在写代码中经常会遇到需要在数组循环中删除数组元素的情况,但删除会导致数组长度变化. package com.fortunedr.thirdReport; import java.util.ArrayList; import java.util.List; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub List<String> list=new Arr