import java.util.*; public class test { public static void main(String[] args) { int i = 0; String str = null; String strZeroOutValue = ""; StringBuffer sb = new StringBuffer("Null test: String initialized as null = "); sb.append(str); sb.append("/n String representing a Zero Out Value:"); sb.append(strZeroOutValue); System.out.println(sb.toString()); try { int [] t = new int[-1]; System.out.println(t.length); } catch( Exception e) { // throws e; } // System.out.println(t.length); // t[0] = 1; int sum = 0; for (i = 0; i < 5; i++) { sum += 0; } /* Random random = new Random();//默认构造方法 int k = 0; for (i = 0; i < 5; i++) { k = random.nextInt(); System.out.println(k); } */ DColorBall t = new DColorBall(); // for(i = 0; i < 20; i++) // { // t.show(); // } int [] c1 = {1,3,4,7,9,11}; int [] c2 = {2,3,4,5,11,13}; int cc = DColorBall.RedFitNum(c1, c2); System.out.println("num = "+cc); } } class DColorBall{ int [] red = new int[6]; int blue; /** * In this way to get the red-ball code, * in order to only using Random 6 times. */ public void SetRedBall() { Random random = new Random();//默认构造方法 int k = 0; int [][] temp = new int[33][2]; for(int i = 0; i < 33; i++) { temp[i][0] = i + 1; temp[i][1] = 0; } for(int i = 0; i < 6; i++) { k = Math.abs(random.nextInt()) % 33; int counts = -1; for(int j = 0; j > -1; j++ ) { if(j == 33) { j = 0; } if(temp[j][1] == 0) { counts++; } if(counts == k) { red[i] = temp[j][0]; temp[j][1] = 1; break; } } } } public void SetBlueBall() { Random random = new Random();//默认构造方法 int k = random.nextInt(); blue = Math.abs(k) % 16 + 1; } public int GetBlueBall() { return blue; } public int[] GetRedBall() { Arrays.sort(red);//升序排序 return red; } public void show() { SetBlueBall(); SetRedBall(); GetRedBall(); // System.out.println("Red ball " ); for(int i = 0; i < 6; i++) { System.out.print(" " + red[i]); } // System.out.println("/nBlue ball " + blue); System.out.println(" = " + blue); } /** * Compare the two code to see how many numbers are same in them; * @param sCode * @param compCode * @return The same number */ public static int RedFitNum(int sCode[], int compCode[]) { int num = 0; int pos = 0; int j = 0; for(int i = 0; i < 6; i++) { for(j = pos; j < 6; j++) { if(compCode[i] == sCode[j]) { num++; pos = j + 1; break; } else if(compCode[i] < sCode[j]) { pos = j; break; } } if(j == 6) { break; } } return num; } }