笔试题汇总,含参考答案(持续更新中。。。)


说明:以下大部分都是测试朋友遇到的笔试题。 

自问自答,自娱自乐,机会只留给有准备的人

技术术语

笔试或者面试的时候,经常被问一些概念,比如同步、异步、阻塞、非阻塞等等,是不是很懵逼?

https://www.cnblogs.com/uncleyong/p/11158806.html

 

linux命令及shell

批量删除/home/test/dist下的所有进程

参考答案:ps -ef | grep '/home/test/dist' | awk '{print $2}' | xargs kill -9

 

对~/test目录下的所有文件进行排序,且2018开头的,在文件名后加上_bak

参考答案:https://gitee.com/UncleYong/exercise/blob/master/modifyFileName.sh

 

数据结构

二叉树遍历:左序、中序、右序

链表操作

 

算法

冒泡排序

二分查找

快速排序

插入

单向链表

链表反转

 

 

编程(python、java) 

 

 

 

 

 

下面结果分别是?

public class Test {
    static String str;
    public static void main(String[] args)
    {
        static String str;
        System.out.println(str);
    }
}

  

public class Test {
    static String str;
    public static void main(String[] args)
    {
        String str;
        System.out.println(str);
    }
}

  

public class Test {
    static String str;
    public static void main(String[] args)
    {
        System.out.println(str);
    }
}

 

类中,jvm给成员变量赋了初始值,不会给局部变量赋初始值,局部变量没有默认值

 

java笔试题:实例属性、静态属性、实例方法、静态方法、构造方法、代码块、静态代码块,他们的执行顺序是?

参考:https://www.cnblogs.com/uncleyong/p/12545986.html

 

【java笔试题】输入带*字符串,把*左移输出,其他字母按原顺序输出,例如:输入“as*c*gkl**o*p*h”,输出******ascgkloph

文末:https://www.cnblogs.com/uncleyong/p/9729189.html

 

对字符串“2kd4-1124*2|^2sdAmZ%fkMcv”排序,并返回符合要求格式的元组数据。

排序规则:按照ASCII码由大到小排序;

返回数据格式:((最大字符,最小字符),(次大字符,次小字符),,,)

参考答案:https://www.cnblogs.com/uncleyong/p/7103947.html

 

倒置输入的整数

参考答案:https://www.cnblogs.com/uncleyong/p/6239433.html

 

结构体存储学生学号、姓名、总分,动态内存分配增加信息,然后排序

参考答案:https://www.cnblogs.com/uncleyong/p/6870252.html

 

数组中有一个数字出现的次数超过数组长度的一半

参考答案:https://www.cnblogs.com/uncleyong/p/6914207.html


将一个字符串中的空格替换成“%20”

参考答案:https://www.cnblogs.com/uncleyong/p/6898204.html


青蛙跳台阶

参考答案:https://www.cnblogs.com/uncleyong/p/7082784.html


找到第一个只出现一次的字符并返回它的位置

参考答案:https://www.cnblogs.com/uncleyong/p/7082893.html

 

python文件操作https://www.cnblogs.com/uncleyong/p/11309729.html

参考答案: 

 

面向对象小测试

第一部分:https://www.cnblogs.com/uncleyong/p/11283647.html

第二部分:https://www.cnblogs.com/uncleyong/p/11289033.html

参考答案:

 

封装一个函数:生成n个密码,要求包含大小写字母,数字,并对密码进行加盐加密,默认盐值%#$123

参考答案:https://gitee.com/UncleYong/exercise/blob/master/passwords.py

 

不用中间变量,交换两个变量(同时为数字 or 同时为字符串)的值

参考答案: https://gitee.com/UncleYong/exercise/blob/master/exchageValu.py

 

运行结果

def fun(arg):
    print(id(arg))
    arg = ['hello']
    print(id(arg))

var = ['ok']
print('var: ',id(var))
fun(var)
print(var)

  

 

【笔试题】局部变量和全局变量

 https://www.cnblogs.com/uncleyong/p/11230413.html

 参考答案: 自己运行,总结规律。

 

下面代码的作用是移除奇数,运行结果是?为什么?

li = [1,1,2,3,4,5,6,7,8,9]
for i in li:
    if i%2!=0:
        li.remove(i)
print(li)

参考答案:[1, 2, 4, 6, 8]

原因:for循环列表的下标,第一次循环,第一个值被移除,列表可变,列表长度减1,同时其它元素下标也变,所以,原来下标为1的第二个元素1,其下标变成0了,此时列表为[1,2,3,4,5,6,7,8,9];第二次循环,找到下标为1的元素2,…

 

在原代码基础上,如何修改为理想中的答案[2,4,6,8]?(必须保留remove)

方式一(逼格低):

li = [1,1,2,3,4,5,6,7,8,9]
li2 = [1,1,2,3,4,5,6,7,8,9]

for i in li2:
    if i%2!=0:
        li.remove(i)
print(li)

方式二(常规思路):

li = [1,1,2,3,4,5,6,7,8,9]
li2 = li.copy()

for i in li2:
    if i%2!=0:
        li.remove(i)
print(li)

 

方案三(高逼格): from:杭州-null-失业老阿姨

li = [1,1,2,3,4,5,6,7,8,9]

for i in li[:]:
    if i%2!=0:
        li.remove(i)
print(li)

其实,更简单的方案是列表生成式

li = list(filter(lambda x:x%2==0, li))

或者

li = [i for i in li if i%2==0]

  

 

一行代码实现1-100奇数求和(5种方案)

 参考答案:https://gitee.com/UncleYong/exercise/blob/master/sumOfOddNumber.py

 

下面的输出结果是?

答案是:[6, 6, 6, 6]

详细解释,参考:https://www.cnblogs.com/uncleyong/p/11208987.html

def multipliers():
    return [lambda x : i * x for i in range(4)]
print([m(2) for m in multipliers()])  

等价于

def func():
    fun_list = []
    for i in range(4):
        def foo(x):
            return x*i
        fun_list.append(foo)
    print(fun_list)
    return fun_list

res_list = []
for m in func():
    res_list.append(m(2))
print(res_list)

  

 

 递归求1-100质数的和

参考答案:https://gitee.com/UncleYong/exercise/blob/master/RecursiveSumOfPrimeNumber.py

非递归参考答案:

print([x for x in range(2, 101) if all([x%y!=0 for y in range(2, x)])])
print(sum([x for x in range(2, 101) if all([x%y!=0 for y in range(2, x)])]))

 

递归求奇数和

def test(n):
    if n==1:
        return 1

    if n%2==1:
        return (n + test(n-2))
    else:
        return test(n-1)

print(test(100))

  

def test(n):
    if n==1:
        return 1

    elif n%2==1:
        return (n + test(n-2))
    else:
        return test(n-1)

print(test(100))

  

 

 

【20190715】要求:封装一个方法,实现文件的读、写、改

 参考答案:https://gitee.com/UncleYong/exercise/blob/master/filetool.py

 

 

【20190712】要求:根据输入的数字n,生成n注大乐透号码,大乐透规则请自行百度

 “35选5加12选2”玩法属于双区选号大乐透,玩法简单易懂,彩民们在购买“35选5加12选2”时,可以从01-35共35个号码中,选取5个号码为前区号码,并从01-12共12个号码中选取2个号码为后区号码,组合为一注进行单式投注。

参考答案:https://gitee.com/UncleYong/exercise/blob/master/lottery_ticket.py

 

【20190711】要求:一行代码,求1-100之间大于10且小于90的数字的平均值

 参考答案:https://gitee.com/UncleYong/exercise/blob/master/oneLineCodeSumBetween11And89.py

 

【20190710】要求:不用sum,最多一个+号,一行代码(不包含导包)实现1到10的累加

备注:只有python实现了一行代码

参考答案(python版):https://gitee.com/UncleYong/exercise/blob/master/MySum.py

参考答案(java版):https://gitee.com/UncleYong/exercise/blob/master/MySum.java

参考答案(shell版):https://gitee.com/UncleYong/exercise/blob/master/MySum.sh  


要求:提取出只包含数字及字母,且以字母开头的最长的子字符串,打印出子字符串及其长度,如果有多个,都要打印出来

testStr = '#ab1k23$%&()*+,-./:;<=ab12w4>?666qzcsbj@[4f]^{1aaa12|}'

比如上面字符串提取结果是:

子字符串ab1k23,长度为6
子字符串ab12w4,长度为6

参考答案(正则):https://gitee.com/UncleYong/exercise/blob/master/findMaxSubString.py

参考答案(非正则):https://gitee.com/UncleYong/exercise/blob/master/findMaxSubString2.py

 

要求:java实现一个类,打印昨天的当前时刻

参考答案:

  https://gitee.com/UncleYong/exercise/blob/master/LastDayTime.java

  https://gitee.com/UncleYong/exercise/blob/master/TestLastDayTime.java  

 

用java编程:输入字符串(中间有若干个空格隔开),要求:以空格隔开,删除空格两边字符串的重复字符再输出,例:aabbbcc ddaaaffggbb变为abc dafgb(注意:输入的空格得保留下来)

方法一:正则

// 用java编程:输入字符串(中间有若干个空格隔开),要求:以空格隔开,删除空格两边字符串的重复字符再输出,
// 例:aabbbcc ddaaaffggbb变为abc dafgb(注意:输入的空格得保留下来)

public class Test
{
    public static void main(String[] args){
//        String s = "aabbbcc ddaaaffggbb";
//        String s = "aaabbbccckkkdaaa";
        System.out.print("请输入字符串:");
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        System.out.println("你输入的原字符串:" + s);
        Test test = new Test();
        String res = test.rmRepeated(s);
        System.out.println("去重之后的字符串:" + res);
    }

    String rmRepeated(String s){
        String str = "";
        for(int i = 0; i<s.length();i++){
            if (str.length()!=0){
                if (str.charAt(str.length()-1)!=s.charAt(i)){
                    str +=s.charAt(i);
                }
                else{
                    String ss = Character.toString(s.charAt(i));
                    Pattern pattern = Pattern.compile("[\\s]");  // 字母:Pattern.compile("[a-zA-Z]"); 数字:Pattern.compile("[0-9]");
                    Matcher matcher = pattern.matcher(ss);
                    if(matcher.find()){
                        str +=s.charAt(i);
                    }
                }
            }
            else{
                str +=s.charAt(i);
            }
        }
        return str;
    }
}

 

方法二:

public class Test
{
    public static void main(String[] args){
//        String s = "aabbbcc ddaaaffggbb";
//        String s = "aaabbbccckkkdaaa";
        System.out.print("请输入字符串:");
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        System.out.println("你输入的原字符串:" + s);
        Test test = new Test();
        String res = test.rmRepeated(s);
        System.out.println("去重之后的字符串:" + res);
    }

    String rmRepeated(String s){
        String str = "";
        for(int i = 0; i<s.length();i++){
            if (str.length()!=0){
                if (str.charAt(str.length()-1)!=s.charAt(i)){
                    str +=s.charAt(i);
                }
                else{
                    String ss = Character.toString(s.charAt(i));  // Sring ss = Sring.valueOf(s.charAt(i));
                    if(ss.equals(" ")){
                        str +=s.charAt(i);
                    }
                }
            }
            else{
                str +=s.charAt(i);
            }
        }
        return str;
    }
}

 

 

【20190709】要求:从左到右,每三位进行反转,例如,输入123456789,输出321654987,如果输入1234567890,输出3216549870

参考答案:https://gitee.com/UncleYong/exercise/blob/master/new_str.py 

 

要求:假如你要为一个应用搞限时促销,生成激活码(或者优惠券)请用 Python 如何生成 200 个激活码(或者优惠券)
激活码的格式为asqE-9xRK-lqWU-QkMT
要求1: 使用随机生成时,生成数字概率为1/5,大写字母和小写字母概率各为2/5
要求2: 这200个激活码,他们各不相同 

参考答案:https://gitee.com/UncleYong/exercise/blob/master/coupon_gen.py 

 

数据库操作(增、删、改、查)

1.一条语句是否使用了索引
2.A,B,C三个字段都建立了索引,组合查询AB,AC,BC哪种不会使用索引
3.写一个查询和更新SQL
4.事物的理解
5.事物的特性

 

以mysql为例,单表插入1万条数据,建表的语句:create table test(id int, name varchar(20));

要求:至少两种方案

参考答案一(存储过程,不传参&传参):https://gitee.com/UncleYong/exercise/blob/master/addDatas.sql

参考答案二(py):https://www.cnblogs.com/uncleyong/p/10938993.html

 

 

一个sql题,查询出grade不一样的人的所有记录

表stu

 

 

参考答案(基于mysql):

方式一:

select * from stu 
	where name in (
		select tt.name from (
			Select t.code,t.name,t.grade  from stu t  group by t.code,t.name,t.grade having count(*)=1) tt);

方式二:

select distinct  s.* from stu s  join(
		select t.code,t.name,t.grade 
		from stu t 
		group by t.code,t.name,t.grade 
		having count(*)=1) s2
where  s.code = s2.code and s.name=s2.name;

 

方式三:(oracle中下面方式写会报错)

 

 

 

 

 

 

 

 

jmeter:
1.怎么做参数化
2.前置处理器和后置处理器的区别
3.bean shell postprocessor怎么这种变量进行参数化
4.聚合报告可以查看到哪些结果

 

Linux:
1.常用命令
2.查看日志 包含订单信息
3.查看一个java进程

性能测试:
1.性能测试关注哪些指标
2.性能测试时cpu使用率过高会怎么处理

java:
1.StringBuffer和StringBuilder的区别
2.LinkedLIst和ArrayList的区别
3.重载和重写的区别
4.重载和重写哪个是在一个类里
5.怎么查看现场阻塞
6.jvm调优会调整哪些参数
7.jdk提供的日志工具
8.MQ是否了解,什么场景使用,kafka
9.什么情况下会fullgc

接口:
1.一个下单接口设计测试用例


自动化:
说一说自动化测试框架,里面包含哪些东西

 

部分图片来源于网络,如有侵权,请联系删除。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM