Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÓÃjavaʵÏֵĵü´úºÍµÝ¹é²åÈëÅÅÐò

ÏÂÃæʹÓÃÒ»¸öjavaʵÏֵĵü´ú°æµÄµÝ¹é°æµÄ²åÈëÅÅÐò¡£
package sort;
import java.util.Date;
import java.util.Random;
/*
* ²åÈëÅÅÐò
*/
public class InsertSort{
public static void main(String args[])
{
int len = 20;
Date date = new Date();
Random random = new Random(date.getSeconds());
int data[]=new int[len];
for(int i = 0; i < len; i++)
{
data[i]=(int)(random.nextFloat()*100+1);
}
show(data);
insertSort(data,data.length);
show(data);
System.out.println(binarySearch(data,1,data.length,55));
System.out.println(binarySearch2(data,55));
insertSortDesc(data);
show(data);
System.out.println(binarySearch(data,1,data.length,55));
System.out.println(binarySearch2(data,55));

}
/*
* ²åÈëÅÅÐòºËÐÄ
*/
private static void insertSortDesc(int[] data)
{
int length = data.length;
for(int i = 1; i < length; i++)
{
int temp = data[i];
int j = i-1;
while(j >= 0 && data[j] < temp)
{
data[j+1] = data[j];
j--;
}
data[j+1] = temp;
}
}

private static void insertSortAsc(int[] data)
{
int length = data.length;
for(int i = 1; i < length; i++)
{
int temp = data[i];
int j = i-1;
while(j >= 0 && data[j] > temp)
{
data[j+1] = data[j];
j--;
}
data[j+1] = temp;
}
}
private static void show(int[] data)
{
System.out.println("========================");
for(int i = 0; i < data.length; i++)
{
System.out.print(data[i] + " ");
}
System.out.println();
System.out.println("========================");
}
/*
* ʹÓõݹéʵÏֵIJåÈëÅÅÐòËã·¨
*/
private static void insertSort(int[] data,int n)
{
if(n>1)
{
insertSort(data,n-1);
merge(data,n-1,n);
}
}
private static void merge(int[] data,int end,int n)
{
int temp=data[n-1];
int i;
for( i=end-1; i>=0; i--)
{
if(data[i]>temp)
data[i


Ïà¹ØÎĵµ£º

Java NIO APIÏê½â

 
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......

Java SE ¶àÏß³Ì

package thread;
class TestThread extends Thread {
 public void run(){
  while(true){
   System.out.println(Thread.currentThread().getName());
  }
 }
}
public class ThreadDemo {
 /**
  * @param args
  */
 public static void ......

Java¶¨Ê±Æ÷

ÔÚÓ¦Óÿª·¢ÖУ¬¾­³£ÐèҪһЩÖÜÆÚÐԵIJÙ×÷£¬±ÈÈçÿ5·ÖÖÓÖ´ÐÐijһ²Ù×÷µÈ¡£ÔÚWEBÏîÄ¿ÖпÉÄÜÐèҪÿ¸ôÒ»¶Îʱ¼ä×Ô¶¯Éú³É¾²Ì¬Ò³£¬×Ô¶¯¼ì²âÊÇ·ñÓÐÐÂÓʼþ£¬¶¨Ê±×Ô¶¯±¸·ÝÎļþµÈ²Ù×÷¡£ÕâЩ¶¼¿ÉÒÔͨ¹ý¶¨Ê±Æ÷TimerÀ´½â¾ö¡£
ÕâÀï½öÌṩ¶¨Ê±Æ÷µÄ²¿·Ö·½·¨ºÍ˵Ã÷£¬¾²Ì¬Ò³Éú³ÉµÈ²Ù×÷¶ÁÕß¿ÉÒÔͨ¹ýÏà¹Ø·½·¨×ÔÐнâ¾ö¡£
¡£¡£¡£°Ù¶È¿Õ¼äÌù´úÂë×ÜÊ ......

Java 7ÒѾ­Íê³ÉµÄÆß´óй¦ÄÜÔ¤ÀÀ

Java 7ÒѾ­Íê³ÉµÄ7´óй¦ÄÜ£º
1£©¶Ô¼¯ºÏÀàµÄÓïÑÔÖ§³Ö£»
2£©×Ô¶¯×ÊÔ´¹ÜÀí£»
3£©¸Ä½øµÄͨÓÃʵÀý´´½¨ÀàÐÍÍƶϣ»
4£©Êý×Ö×ÖÃæÁ¿Ï»®ÏßÖ§³Ö£»
5£©switchÖÐʹÓÃstring£»
6£©¶þ½øÖÆ×ÖÃæÁ¿£»
7£©¼ò»¯¿É±ä²ÎÊý·½·¨µ÷Óá£
ÏÂÃæÎÒÃÇÀ´×Ðϸ¿´Ò»ÏÂÕâ7´óй¦ÄÜ£º
¶Ô¼¯ºÏÀàµÄÓïÑÔÖ§³Ö
Java½«°üº¬¶Ô´´½¨¼¯ºÏÀàµÄµÚÒ»ÀàÓïÑÔÖ§³Ö¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ