栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java笔试录系列

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java笔试录系列

基础笔试题
public class Test1 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        List list = new ArrayList<>();
        Class c = list.getClass();
        Method method = c.getMethod("add",Object.class);
        method.invoke(list,"a");
        System.out.println(list);
    }
}

public class Test2 {

    public static int[] twoSum(int[] nums, int target) {
        Map map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int complement = target - nums[i];
            if (map.containsKey(complement)) {
                return new int[] { map.get(complement), i };
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution");
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2,7,11,15};
        System.out.println(Arrays.toString(twoSum(nums, 9)));
    }
}

public class Test3 {
    public static int  f(){
        int b = 0;
        try {
            b = 1;
            return b + 1;
        }finally {
            b = b - 1;
            System.out.println(b);
        }
    }

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

public class Test4 {
    public static void main(String[] args) {
        float a = 0.125f;
        double b = 0.125d;
        System.out.println((a-b) == 0);
    }
}

public class Test5 {
    public static void main(String[] args) {
        int a = 127;
        Integer b = 127;
        Integer c = 127;
        Integer d = 128;
        Integer e = 128;
        // true
        System.out.println(a == b);
        // true
        System.out.println(b == c);
        // false
        System.out.println(d == e);
    }
}

public class Test6 {
    public static void main(String[] args) {
        String a = "a";
        String b = "b";
        String result = "ab";
        String result1 = String.valueOf("ab");
        String result2 = new String("ab");
        String result3 = a + b;
        String result4 = "a" + "b";
        String result5 = "ab";
        System.out.println(a+b == result4);
    }
}

public class Test7 {
    public static void main(String[] args) {
        System.out.println(B.c);
    }
}

class A {
    static {
        System.out.println("A");
    }
}

class B extends A {
    static {
        System.out.println("B");
    }
    // 输出ABC
    public static String c = new String("C");
    // 输出C
    // public static final String c = "C";
}
Switch支持的数据类型 char, byte, short, int, Character, Byte, Short, Integer, String,enum

枚举编写

public class Constants {

    public enum StatusEnum{

        ENABLE(0,"启用"),
        DISABLE(1,"停用"),
        DELETE(2,"删除");

        private final Integer code;
        private final String message;

        StatusEnum(Integer code, String message){
            this.code = code;
            this.message = message;
        }
        public Integer getCode() {
            return code;
        }
        public String getMessage() {
            return message;
        }

    }

}

public interface IConstants {

    class UserStatus {
        public static final String ENABLE = "1";
        public static final String DISABLE = "0";
    }

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/340531.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号