面试/笔试经历--SQL(括号匹配问题)(jdk底层SuString)---weimob

来源:互联网 发布:通联数据待遇怎么样 编辑:程序博客网 时间:2024/05/16 19:23

一张数据表



1.查询所有成绩大于80分的学生的名字

select DISTINCT a.name from grade a 

where a.name not in (

select DISTINCT s.name from grade s 

where s.score < 80

)



加上DISTINCT(截然不同的) 意义为去掉重复项   在里面查询的表中 如果查到的是两个小红 所以里面的也要用到DISTINCT



2.查询平均成绩大于80分的学生姓名

select a.name,a.avg from (

select name,AVG(score) as avg from grade group by name

) a

where a.avg >80


注意:在AVG函数之后,要加上as avg 取上一个名字来代称 否则会报错

其他的类似于 最大值最小值 取不同的函数即可 MIN()  MAX() 等等


一个经常见到的编程题

(从这个时候我才知道了java也是有stack栈的,枉费我学习java近乎两年,学习不精,实在该检讨)


那么接下来的问题,就与栈有关了 

很常见的编程题 关于括号匹配 

import java.util.Stack;
public class StackProblem{    public static void main(String[] args)    {        String str = "(())、()";        boolean flag= new StackProblem().check(str);        System.out.println("这个字符串为:"+flag);    }            public boolean check(String str){        int length = str.length();        Stack<Character> stack = new Stack<Character>();        for(int i=0;i<length;i++){            if(str.charAt(i)==')'){                stack.pop();            }else if(str.charAt(i)=='('){                stack.push(str.charAt(i));            }else if(str.charAt(i)=='、'){                //则遇到的就是、了 此时如果栈里有元素 那么一定不匹配 没有元素就可以继续了               if(!stack.empty()){                   //非空 直接返回false                   return false;               }            }        }        if(stack.empty()){            return true;        }else{            return false;        }            }}
3.String.substring(beginIndex,endIndex);

那么这就是考你的JDK底层到底看了多少东西了呢,实话是如果真没看过,那是真不会。最常见的也说不上来,先把遇到的贴上去把。

  /**     * Returns a string that is a substring of this string. The     * substring begins at the specified {@code beginIndex} and     * extends to the character at index {@code endIndex - 1}.     * Thus the length of the substring is {@code endIndex-beginIndex}.     * <p>     * Examples:     * <blockquote><pre>     * "hamburger".substring(4, 8) returns "urge"     * "smiles".substring(1, 5) returns "mile"     * </pre></blockquote>     *     * @param      beginIndex   the beginning index, inclusive.     * @param      endIndex     the ending index, exclusive.     * @return     the specified substring.     * @exception  IndexOutOfBoundsException  if the     *             {@code beginIndex} is negative, or     *             {@code endIndex} is larger than the length of     *             this {@code String} object, or     *             {@code beginIndex} is larger than     *             {@code endIndex}.     */    public String substring(int beginIndex, int endIndex) {        if (beginIndex < 0) {            throw new StringIndexOutOfBoundsException(beginIndex);        }        if (endIndex > value.length) {            throw new StringIndexOutOfBoundsException(endIndex);        }        int subLen = endIndex - beginIndex;        if (subLen < 0) {            throw new StringIndexOutOfBoundsException(subLen);        }        return ((beginIndex == 0) && (endIndex == value.length)) ? this                : new String(value, beginIndex, subLen);    }

但是整个提炼下来,我绝得面试 的人其实看的主要还是就一行代码

return ((beginIndex == 0) && (endIndex == value.length)) ? this                 : new String(value, beginIndex, subLen);


自己尝试一下 return ((beginIndex==0) && (endIndex==value.length) ) ?  this 

                                     : new String(value,beginIndex,sublen);

以上.......校招的漫长之路,就这样吧。