摘要:
1 import java.util.Arrays; 2 3 public class Day041 4 { 5 static void bubbleSort(int[] arr) 6 { 7 for (int i = 0; i < arr.length - 1; i++) 8 { 9 for (int j = i + 1; j < arr.length; j++)10 {11 if (arr[j] < arr[i])12 {13 ... 阅读全文
posted @ 2014-01-02 19:51
一路向北中
阅读(134)
评论(0)
推荐(0)
摘要:
1 public class Day042 2 { 3 public static void main(String[] args) 4 { 5 int[] arr = new int[]{1, 4, 5, 7, 9, 14, 24}; 6 System.out.print(halfSearch(arr, 6)); 7 } 8 static int halfSearch(int[] arr, int x) 9 {10 int min = 0;11 int max = arr.length ... 阅读全文
posted @ 2014-01-02 19:48
一路向北中
阅读(244)
评论(0)
推荐(0)
摘要:
首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。.以此类推,直到所有元素均排序完毕。注:此方法直接对堆内存进行操作,故效率不高! 1 static void selectSort(int[] arr) 2 { 3 System.out.println(Arrays.toString(arr)); 4 for (int i = 0; i < arr.length; i++) 5 { 6 for (int j = i +... 阅读全文
posted @ 2014-01-02 19:45
一路向北中
阅读(167)
评论(0)
推荐(0)
摘要:
1, Random r = new Random(); System.out.println(r.nextInt());//nextInt()方法返回一个int类型的数值,有正数也有负数。 r.nextInt(100);产生100以内的数。2, System.out.println(Math.random());//返回一个小于1,大于0的double类型的数。JAVA产生指定范围的随机数产生机制: 产生Min-Max之间的数字实现原理: Math.round(Math.random()*(Max-Min)+Min)long Temp; //不能设定为int,必须设定为long//产生10.. 阅读全文
posted @ 2014-01-02 19:40
一路向北中
阅读(174)
评论(0)
推荐(0)
摘要:
1 public static void selectSort3(Comparable[] array) 2 { 3 System.out.println("===========Insert Sort Started==========="); 4 Comparable temp; 5 int min; 6 for (int index = 0; index < array.length; index++) 7 { 8 // 假定第一个元素为最小元素 9 ... 阅读全文
posted @ 2014-01-02 19:37
一路向北中
阅读(128)
评论(0)
推荐(0)
摘要:
1 static void bubbleSort(int[] arr) 2 { 3 for (int i = 0; i < arr.length - 1; i++) 4 { 5 for (int j = 0; j < arr.length - i - 1; j++) 6 { 7 if (arr[j] < arr[j + 1]) 8 { 9 arr[j] = arr[j] ^ arr[j + 1]... 阅读全文
posted @ 2014-01-02 19:34
一路向北中
阅读(151)
评论(0)
推荐(0)
摘要:
与&:同真为真,一假则假;或|:同假才假,一真即真;异或^:相同为假,相异为真非!:非真即假,非假即真。 阅读全文
posted @ 2014-01-02 19:08
一路向北中
阅读(191)
评论(0)
推荐(0)
摘要:
1, c=a; a=b; b=c;2,n = n + m;//如果n和m的值非常大,容易超出int范围。m = n - m;n = n - m;3,n = n ^ m;m = n ^ m;//(n^m)^m;n = n ^ m;//n ^ (n ^ m)注: 上述方法在执行多次后,第二种方法效率会高一些,在只执行一次或者少次的情况下第一,三两种方法反而效率高一些。所以第一种方法在少量运算的情况下,比较好。在多次的时候第二种比较好。 1 import java.util.Random; 2 3 public class Day042 4 { 5 public static void m... 阅读全文
posted @ 2014-01-02 18:48
一路向北中
阅读(1004)
评论(0)
推荐(0)
摘要:
当比较包装类里面的数值是否相等时,用equals()方法;当测试两个包装类的引用是否指向同一个对象时,用==。 阅读全文
posted @ 2014-01-02 18:39
一路向北中
阅读(180)
评论(0)
推荐(0)
摘要:
函数重载 跟返回值无关 跟参数个数及参数类型有关 阅读全文
posted @ 2014-01-02 18:34
一路向北中
阅读(102)
评论(0)
推荐(0)
摘要:
for(;;){} 阅读全文
posted @ 2014-01-02 18:33
一路向北中
阅读(104)
评论(0)
推荐(0)
摘要:
1 public class Day042 2 { 3 public static void main(String[] args) 4 { 5 changeI(60); 6 System.out.print(toUnsignedString(60, 4)); 7 } 8 static void changeI(int x) 9 {10 int temp = x;11 StringBuffer sb = new StringBuffer();12 while ((temp ... 阅读全文
posted @ 2014-01-02 18:32
一路向北中
阅读(467)
评论(0)
推荐(0)
摘要:
1 public class Day042 2 { 3 public static void main(String[] args) 4 { 5 int a = 3; 6 int b = 1; 7 printResult1(a, b); 8 printResult2(a, b); 9 printResult3(a, b);10 printResult4(a, b);11 }12 static void printResult1(int a, int b)13 ... 阅读全文
posted @ 2014-01-02 18:20
一路向北中
阅读(147)
评论(0)
推荐(0)

浙公网安备 33010602011771号