import java.util.*; //把util这个包下的全部类导入到程序中
public class yuansucunzaifou{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
//当程序需要从键盘获取用户输入的命令或数据时,相当于scanf
int []a = {12,34,9,23,45,6,90,123,19,34};
Arrays.sort(a);//对数组进行排序
//System.out.println (Arrays.toString (a)); 遍历并输出整个数组
System.out.println(Arrays.toString(a));
System.out.println("输入整数,程序判断该程序是否在数组中");
int number = scanner.nextInt(); //只会读取数值,并且会以回车结束
int index = Arrays.binarySearch(a,number); /*Arrays类的binarySearch()方法,
*可以使用二分搜索法来搜索指定的数组,以获得指定对象。该方法返回要搜索元素的索引值。
*务必注意:数组必须经过排序才可以使用此方法,否则返回下标显示不准。*/
if(index>=0)
System.out.println(number+"和数组中索引为"+index+"的元素值相同");
else
System.out.println(number+"不与和数组中任何的元素值相同");
}
}
//输出结果会以从小到大的顺序排列