第七章单元测试
  1. 测试如下代码:

      public class Ref{

       public static void main(String[] args)  {

         StringBuffer sbl = new StringBuffer("Hello");

         StringBuffer sb2 = new StringBuffer("Hello");

         boolean result = sbl.equals(sb2);

         System.out.println(result);

       }

     }

     下述哪条语句正确描述了程序编译和运行的行为?


  2. A:编译成功,输出为 1 B:编译成功,输出为 0 C:编译成功,输出为 true D:编译成功,输出为 false
    答案:编译成功,输出为 false
  3. String alphabet="ABCDEFGHIJKLMNOPQ"

    调用alphabet.substring(6,10)返回什么子字符串?


  4. A:CDEF B: GHIJ C:FGHI D:EFGH
  5. 以下程序的调试结果为?
     1. public class EqualsTest{
     2.   public static void main(String args[]){
     3.     Long LA = new Long(7);
     4.     Long LB = new Long(7);
     5.     if(LA==LB) System.out.println("Equal");
     6.     else System.out.println("Not Equal");
     7.    }
     8. }



  6. A:编译错误 B: 程序在执行到第5行时出现异常 C:输出"Equal" D:输出"Not Equal"
  7. 有如下代码:
    public class Test{  
       public static void main(String args[]) {  
         String  str = new String("World");
         char  ch[] = {'H','e','l','l','o'};
         change(str,ch);  
         System.out.println(str + "and" + ch);
       }
       public static void change(String str, char ch[]) {
          str = "Changed";
          ch[0] = 'C';
       }
    }
    运行后输出的结果是:


  8. A:Changed and Cello B:World and Cello C:World and Hello D:World and CelloChanged and Hello
  9. 已知代码:  String s = "story";下列语句中合法的是:



  10. A:String t = s.toLowerCase(); B:s += "books"; C:int len = s.length; D:char c = s[1];

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(1) dxwkbang
返回
顶部