zoukankan      html  css  js  c++  java
  • http://www.jobui.com/mianshiti/it/java/6782/

    1、运算符优先级问题,下面代码的结果是多少?(笔试)

    package test;


    public class Test {
    public static void main(String[] args) {
    int k = 0;
    int ret = ++k + k++ + ++k + k;
    // ret的值为多少
    System.err.println(ret);
    }
    }
    2. 运算符问题,下面代码分别输出什么?(笔试)

    package test;

    public class Test {
    public static void main(String[] args) {
    int i1 = 10, i2 = 10;
    System.err.println(“i1 + i2 = ” + i1 + i2);
    System.err.println(“i1 – i2 = ” + i1 – i2);
    System.err.println(“i1 * i2 = ” + i1 * i2);
    System.err.println(“i1 / i2 = ” + i1 / i2);
    }
    }
    3. 下面代码的结果是什么?还是抛出异常?(笔试)
    package test;

    public class Test {

    public void myMethod(String str) {
    System.err.println(“string”);
    }

    public void myMethod(Object obj) {
    System.err.println(“object”);
    }

    public static void main(String[] args) {
    Test t = new Test();
    t.myMethod(null);
    }
    }
    4. 假设今天是9月8日,下面代码输出什么?(笔试)
    package test;

    import java.util.Date;

    public class Test {

    public static void main(String[] args) {
    Date date = new Date();
    System.err.println(date.getMonth() + ” ” + date.getDate());
    }
    }
    5. 下面代码的输出结果是什么?
    package test;

    public class Test {

    public static void main(String[] args) {
    double val = 11.5;
    System.err.println(Math.round(val));
    System.err.println(Math.floor(val));
    System.err.println(Math.ceil(val));
    }
    }
    6. 编程输出一个目录下的所有目录及文件名称,目录之间用tab。(笔试)
    package test;

    import java.io.File;

    public class Test {

    public static void main(String[] args) {
    new Test().read(“D:/test”, “”);
    }

    public void read(String path, String tab) {
    File file = new File(path);
    File[] childFiles = file.listFiles();
    for (int i = 0; childFiles != null && i < childFiles.length; i++) {
    System.err.println(tab + childFiles.getName());
    if (childFiles.isDirectory()) {
    read(childFiles.getPath(), tab + “ ”);
    }
    }
    }
    }

    不要觉得很简单,最起码你要记得返回当前文件夹下的所有文件的方法是listFiles(),isDirectory别拼错了。
    7、从键盘读入10个整数,然后从大到小输出。(笔试)
    package test;

    import java.util.Arrays;
    import java.util.Comparator;
    import java.util.Scanner;

    public class Test {

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    // 注意这里的数组,不是int的
    Integer[] arr = new Integer[10];
    for (int i = 0; i < 10; i++) {
    arr = in.nextInt();
    }
    Arrays.sort(arr, new Comparator() {
    @Override
    public int compare(Integer o1, Integer o2) {
    if (o1 > o2) return -1;
    if (o1 < o2) return 1;
    return 0;
    }

    });
    System.err.println(Arrays.toString(arr));
    }

    }

    自己手写排序算法的可以无视此题,如果是Arrays.sort()的,请注意Comparator与Comparable接口的区别,别搞混了。
    8、下面代码的结果是什么?
    package test;

    public class Test extends Base {

    public static void main(String[] args) {
    Base b = new Test();
    b.method();

    Test t = new Test();
    t.method();
    }

    @Override
    public void method() {
    System.err.println(“test”);
    }

    }

    class Base {
    public void method() throws InterruptedException {
    System.err.println(“base”);
    }
    }
    9、以下代码的结果是什么?

    package test;

    public class Test extends Base {

    public static void main(String[] args) {
    new Test().method();
    }

    public void method() {
    System.err.println(super.getClass().getName());
    System.err.println(this.getClass().getSuperclass().getName());
    }

    }

    class Base {
    }
    10、true or false?

    package test;

    public class Test {

    public static void main(String[] args) {
    String str1 = new String(“abc”);
    String str2 = new String(“abc”);
    System.err.println(str1.equals(str2));

    StringBuffer sb1 = new StringBuffer(“abc”);
    StringBuffer sb2 = new StringBuffer(“abc”);
    System.err.println(sb1.equals(sb2));
    }
    }

  • 相关阅读:
    LeetCode 1
    Thinking in Java学习杂记(第7章)
    工程优化部分概念
    Thinking in Java学习杂记(5-6章)
    Thinking in Java学习杂记(1-4章)
    python中map()和dict()的用法
    JavaWeb高级编程(下篇)
    对CSDN的理性吐槽
    CSDN博客已经打不开了
    大连交大教务一键教学评价
  • 原文地址:https://www.cnblogs.com/xiohao/p/3397531.html
Copyright © 2011-2022 走看看