a^b^b = a(得到本身)位运算是最快的运算方法
public class TestSwitch{ public static void main(String args[]) { int a = 0; switch(a){ default : System.out.println("default"+a); case 1: System.out.println(" case 1"+a); //break; case 2: System.out.println("- case 2"+a); break; case 3: System.out.println(" case 3"+a); break; case 4: System.out.println(" case 4"+a); break; } } }
package xyxy.sjxy.day004; public class SortArr{ public static void main(String args[]){ int [] arr = new int[]{4,5,2,6,8,9,0}; sort1(arr); //(arr ); //sort2(arr ); //sysArr(arr ); int position = insertPostion(arr,0); System. out.println(position); sysArr(arr); } //选择排序 public static void sort1(int[] arr){ for(int i = 0; i < arr.length - 1; i ++){ for(int j = i + 1; j < arr.length; j ++){ if(arr[i] > arr[j]){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } } //输出数组的数据 public static void sysArr( int [] arr){ System. out.print("[" ); for(int i = 0 ; i < arr.length; i ++){ if(i == arr.length - 1){ System. out.print(arr[i]+"]" ); } else{ System. out.print(arr[i]+"," ); } } } //冒泡排序 public static void sort2(int[] arr){ for(int i = 0; i < arr.length - 1; i ++ ){ for(int j = 0 ; j < arr.length - i - 1; j ++){ if(arr[j] < arr[j + 1]){ int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } //往一个有序的数组中插入数据,使数组还是有序状态二份查找要插入的位置 public static int insertPostion(int[] arr, int key){ int min = 0,max = arr.length - 1,mid = (min + max) / 2 ; while(min <= max){ if(arr[mid] > key){ max = mid - 1; } else if (arr[mid] < key){ min = mid + 1; } else{ return mid; } mid = (min + max) / 2 ; } return -1; } }
public void toEr(int x) { StringBuffer sb = new StringBuffer(); int sum = x % 2; sbappend(sum); sum >>1; }
public void toShiLiu(int x){ char [] chs = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d'}; SringBuffer sb = new StringBuffer(); for(int i = 0; i < 8; i ++){ int sum = x & 15; // if(sum > 9) // sum = (char)(sum - 10 +'a'); // sb.append(sum); //还可用查表法来找对应的十六进制数值: sb.append(sum[i]); x >>> 4; sum.reverse(); } }
package xyxy.sjxy.day004; public class ToArray{ public static void main(String args[]){ toArray(60,4); } //定义一个公共的转换进制的方式: public static void toArray(int sum, int b){ char[] chs = {'0','1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'a' ,'b' ,'c' ,'d' ,'e' }; char[] chars = new char[32/b]; int position = chars.length ; while(sum != 0){ int temp = sum & ((1<<b)-1); chars[--position] = chs[temp]; sum = sum>>>b; } for(int i = position-1 ; i < chars.length; i++ ){ System. out.println(chars[position]); } } }
原文地址:http://blog.csdn.net/u011218159/article/details/43897831