标签:demo 二分 bsp nbsp ati arch ++ 有序数组 oid
1 package demo04; 2 3 import java.util.Arrays; 4 5 public class ArraysDemo { 6 public static void main(String[] args) { 7 8 //static void sort(任意类型数组) 对数组升序排列 9 int[] arr = {5,1,2,6,3}; 10 Arrays.sort(arr); 11 for (int i = 0; i < arr.length; i++) { 12 System.out.println(arr[i]); 13 } 14 15 //static int binarySearch(数组, 被查找的有序数组) 二分查找 返回负数(-插入点-1) 16 int[] arr1 = {1,2,3,4,5,6}; 17 int index = Arrays.binarySearch(arr1, 3); 18 System.out.println(index); 19 20 //static String toString(数组) 将数组转为字符串 21 int[] arr2 = {1,2,3,4,5,6}; 22 String s = Arrays.toString(arr2); 23 System.out.println(s); 24 25 } 26 }
标签:demo 二分 bsp nbsp ati arch ++ 有序数组 oid
原文地址:http://www.cnblogs.com/lwn007/p/6880490.html