2012-04-23总结
?
import java.io.File;import java.lang.reflect.Field;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;public class A {// 给你一组字符串如:iu7i8hy4jnb2,让你编程输出里面的数字:7842public static void printNumber(String testString) {for (int i = 0; i < testString.length(); i++) {char a = testString.charAt(i);if (a - '0' >= 0 && a - '9' <= 0) {System.out.println(a);}}}// 给你一组字符如{1,3,4,7,2,1,1,5,2},让你输出里面出现次数最多且数值最大的一个,出现几次public static void fun4() {int[] a = { 1, 2, 3, 4, 7, 9, 6, 1, 1, 1, 9, 1, 1, 1, };Arrays.sort(a);for (int i = 0; i < a.length; i++) {System.out.print(a[i] + " ");}int maxNumber = a[a.length - 1], maxCount = 1;int curNumber, curCount = 1;for (int i = a.length - 1; i > 0; i--) {curNumber = a[i];if (a[i] == a[i - 1] && i != 1) {curCount++;} else {if (curCount > maxCount) {maxCount = curCount;maxNumber = curNumber;}curCount = 1;}}System.out.println("\nmaxCount: " + maxCount + ",maxNumber: " + maxNumber);}// 给你一组字符如{1,3,4,7,2,1,1,5,2},让你输出里面出现次数最多且数值最大的一个,出现几次public static void haveFun() {int[] a = { 9, 1, 3, 2, 2, 3, 4, 5, 6, 7, 7, 8, 8, 7, 7, 7, 7, 7, 7 };Arrays.sort(a);int maxNumber = a[a.length - 1], maxCount = 1, currentNumber = a[0], currentCount = 1;for (int i = a.length - 1; i > 0; i--) {currentNumber = a[i];if (a[i] == a[i - 1] && i != 1) {currentCount++;} else {if (currentCount > maxCount) {maxCount = currentCount;maxNumber = currentNumber;}currentCount = 1;}}System.out.print("\nmaxCount: " + maxCount + ",maxNumber: " + maxNumber);}// 给你一组字符串让你把它倒叙输出(利用StringBuffer的reverse()方法)public static void pordwed(String pordwed) {StringBuffer sb = new StringBuffer(pordwed);String s1 = (sb.reverse()).toString();System.out.println(s1);}// 假设字符串类似这样的aba和aab就相等,现在随便给你二组字符串,请编程比较他们看是否相等public static boolean myEquals(String s1, String s2) {//if (s1.length() != s2.length()) {//return false;//}//char[] arrayS1 = s1.toCharArray(), arrayS2 = s2.toCharArray();//Set resultS1 = new HashSet();//Set resultS2 = new HashSet();//for (int i = 0; i < arrayS1.length; i++) {//resultS1.add(arrayS1[i]);//}//for (int i = 0; i < arrayS2.length; i++) {//resultS2.add(arrayS2[i]);//}//return resultS1.size() == resultS2.size();char[] c1 = s1.toCharArray();char[] c2 = s2.toCharArray();Arrays.sort(c1);Arrays.sort(c2);return Arrays.toString(c1).equals(Arrays.toString(c2));}// *创建一个静态方法,给它传入一个对象,请循环的打印出该对象所在类的类名和所实现的方法名,以及属性名,并且按照名称大小public static void allProperty(Object object) {System.out.println("类名: " + object.getClass().getName());List propertyList = new ArrayList<String>();Method[] method = object.getClass().getDeclaredMethods();for (int i = 0; i < method.length; i++) {propertyList.add(method[i].getName());}Field[] fields = object.getClass().getDeclaredFields();for (int i = 0; i < fields.length; i++) {propertyList.add(fields[i].getName());}Collections.sort(propertyList);for (Object property : propertyList) {System.out.println((String) property);}}// 求两个数的公约数,M,Npublic static void divisor(int a, int b) {List as = new ArrayList();for (int i = 1; i <= a; i++) {if (a % i == 0 && b % i == 0) {as.add(i);}}// as.retainAll(bs);//排除,相当于求了交集 **!Iterator lit0 = as.listIterator();while (lit0.hasNext()) {System.out.print(" " + lit0.next());}}// 实现数组复制Object 的clone() 方法public static void sortArray() {int[] a = { 3, 43, 1, 2, 5, 7, 12, 44 };int[] b = (int[]) a.clone();for (int i : b) {System.out.print(" " + i);}}// 编程显示某一文件目录下的文件名public static void listAllFile(String path,String tab) {File file = new File(path);File[] files = file.listFiles();for (int i = 0; files != null && i < files.length; i++) {System.out.println(tab + files[i].getName());if (files[i].isDirectory()){listAllFile(files[i].getPath() , tab + "\t");}}}public static void main(String args[]) {// printNumber("iu7i8hy4jnb2");// char[] a = { 1, 3, 4, 7, 2, 1, 1, 5, 2 };// printMoreNumber(a);// pordwed("aaaabc");// haveFun();// replaceAll()方法的正则匹配// System.out.println("iu7i8hy4jnb2 ".replaceAll( "[^\\d]", "")); System.out.println(myEquals("aab", "aba"));// Test t = new Test();// allProperty(t);// divisor(10, 8);//sortArray();//listAllFile("C:\\Users\\Percival\\Desktop\\work","");}}class Test {private String storm;private String fuck;private String you;void function1() {}void function2() {}void function3() {}void function4() {}}