java学习笔记之Arrays类(二分查找)

ARM 201浏览
import java.io.*; import java.util.*; import java.math.*; import java.text.*; public class Main { 	public static void main(String[] args){ 		Scanner in=new Scanner(System.in); 		int x,n; 		while(in.hasNext()){ 			n=in.nextInt(); 			int[] a=new int[n]; 			for(int i=0;i<n;i++) 				a[i]=in.nextInt(); 			Arrays.sort(a); 			x=in.nextInt(); 			if(Arrays.binarySearch(a,x)>=0) 				System.out.println("YES"); 			else 				System.out.println("NO"); 		} 	} }