面试
//成绩表A,三列:姓名,性别,成绩,按成绩[80-100],[60-80),60以下 三档进行分组统计除了第一种解法外还有其他哪种解法?
select case when score>=80 and score<=100 then '优'
when score>=60 and score <=80 then '良'
else '差' end as '成绩范围',count(*) as '人数' from scoretable GROUP BY case when score>=80 and score<=100 then '优'
when score>=60 and score <=80 then '良'
else '差' end
**编程题
**
//给定一个有序数组如:[1,2,3,4,5],从数组中查找指定的数据,存在返回对应的索引位置,不存在返回-1 上代码,除了这两种还有哪些解题思路?
public class TestMain {
public static void main(String[] args) {
//给定一个有序数组如:[1,2,3,4,5],从数组中查找指定的数据,存在返回对应的索引位置,不存在返回-1
int index[]={1,2,3,4,45,8,9,10,6};
// int result = search(index,5);
// System.out.println(result);
int result = getIndex(index,6);
System.out.println(result);
}
public static int getIndex(int[] arr,int target){
if(arr!=null&&arr.length!=0){
for (int i=0;i<arr.length;i++){
if (arr[i]==target){
return i;
}
}
}
return -1;
}
/**
*
* @param arr
* @param target
* @return
*/
public static int search(int[] arr,int target){
int left = 0;
int right = arr.length-1;
while(left<=right){
int mid = (left+right)/2;
if(arr[mid]==target){
return mid;
}else if(arr[mid]<target){
left = mid+1;
}else{
right = mid-1;
}
}
return -1;
}
}