java基础测试题(1)

来源:互联网 发布:天津买菜用什么软件 编辑:程序博客网 时间:2024/06/05 17:22

1、使用String类的哪个方法可以让字符串”ABCdef”和字符串”abcDEF”比较的返回值是true?(    )

 

2下面代码的输出结果是?(  
    public class General { // 新建类
     public static void main(String[] args) { // 主方法
     String str = String.format("%x", 200);
     System.out.println(str);
     }
    } 

    A200 

    Bfe 

    Cc8 

    D160

 

3、正则表达式“\D”表示所有的(  )字符串。

 

4、下面代码的输出结果是?(  )
    public class Join { // 创建类
     public static void main(String args[]) { // 主方法
     String s1 = new String("中国"); // 声明String对象s1
     String s2 = new String("加油"); // 声明String对象s2
     String s = s1 + " " + s2;
     System.out.println(s); // 将s输出
     }
    }

 

5、StringBuilder类的(    )方法的作用是追加字符串到StringBuilder类的对象中 

6”abcdefg”.substring(27) 的结果是?(  ) 

    A.cdefg 

    B.bcdefg 

    C.abcdefg 

    D.无法编译

7、在编译和运行下列代码时会发生什么?(  )
    public class Ref {
     public static void main(String args[]) {
     String str = "123456789";
     char mychar = str.charAt(9);
     System.out.println(mychar);
     }
    }

 A.编译错误 

 B.输出9 

 C.输出123456789 

 D.运行时出现错误

 

8、当编译和运行下列代码时会发生什么?(  )
    public class Test {
        public static void main(String[] args) {
            String text = "ABCD";
            text += "E";
            text.replace("C", "F");
            System.out.println(text);
        }
    }

 

9下列代码中newstr变量的值应该是“PoPPet”。(    
    String str = " poppet "; // 定义字符串str
    String newstr = str.replace("p", "P"); 

    A.正确 

    B.错误

10 ”abcdefg”.substring(3)的返回值是?(  ) 

    Adefg 

    Bcdefg 

    Cabc 

    D.空字符串

 

 

11获取字符串长度的方法和获取数组长度相同,读取其length属性就可以。(   ) 

     A.正确 

    B.错误

0 0
原创粉丝点击