摘要: 1 public class Day05 2 { 3 int t = 2; 4 5 public static void main(String[] args) 6 { 7 int t = 1; 8 System.out.println(t); 9 System.out.println(new Day05().t);10 }11 12 } 阅读全文
posted @ 2014-01-10 09:39 一路向北中 阅读(182) 评论(0) 推荐(0)
摘要: 1 class CodeDemo01 2 { 3 CodeDemo01() 4 { 5 System.out.println("CodeDemo01构造方法"); 6 } 7 8 { 9 System.out.println("CodeDemo01代码块");// 在new CodeDemo01 时 才执行这句,而且是在main后10 }11 12 public static void main(String[] args)13 {14 System.out.println("CodeD... 阅读全文
posted @ 2014-01-09 15:37 一路向北中 阅读(186) 评论(0) 推荐(0)
摘要: 1 public static void main(String[] args) 2 { 3 System.out.println("main"); 4 w: for (int x = 0; x < 3; x++) 5 { 6 for (int y = 0; y < 4; y++) 7 { 8 System.out.println("x=" + x); 9 break w;10 }11 ... 阅读全文
posted @ 2014-01-09 15:09 一路向北中 阅读(143) 评论(0) 推荐(0)
摘要: java1. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆。2. 栈的优势是,存取速度比堆要快,仅次于直接位于CPU中的寄存器。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。另外,栈数据可以共享,详见第3点。堆的优势是可以动态地分配内存大小,生存期也不必事先告诉编译器,Java的垃圾收集器会自动收走这些不再使用的数据。但缺点是,由于要在运行时动态分配内存,存取速度较慢。3.Java中的数据类型有两种。一种是基本类型(primitivetypes), 共有8种,即int,short, l 阅读全文
posted @ 2014-01-07 15:50 一路向北中 阅读(211) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2014-01-03 10:23 一路向北中 阅读(100) 评论(0) 推荐(0)
摘要: 1 public class Day043 2 { 3 // 查表法进制转换 4 public static void main(String[] args) 5 { 6 System.out.print(getChange(16, 8)); 7 } 8 // 定义数组 9 static char[] arr = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8',10 '9', 阅读全文
posted @ 2014-01-03 09:49 一路向北中 阅读(292) 评论(0) 推荐(0)
摘要: 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)