example8_3.java

来自「《Java程序设计与应用》-张仕斌-源程序 《Java程序设计与应用》-张仕斌」· Java 代码 · 共 35 行

JAVA
35
字号
/*
 * Example8_3.java
 *
 * Created on 2006年9月16日, 上午10:26
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package example8_3;
import java.util.Arrays; //导入Arrays类

/**
 *
 * @author Administrator
 */
public class Example8_3 {
    
    /** Creates a new instance of Example8_3 */
    public Example8_3() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic 
        int vec[] = {-5, 19, 23, 37, 47, 56}; 
        int slot = Arrays.binarySearch(vec, 35);  //折半法查找35在数组vec中的位置
        slot = -(slot + 1);   //插入点位置
        System.out.println("insertion point =  "+ slot); 
    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?