常用数据类型处理类

常用数据类型处理测验

1、单选题:
​写出以下程序的运行结果?‎public class Test{‎   public static void main(String argv[]){‎      String s = new String("hello");‎      myMethod(s);‎      System.out.print("s=" + s);‎   }‎   public static void  myMethod(String s){‎      s = s + "!";‎   }‎}‎
选项:
A: s=hello!
B: s=hello
C: hello!
D: hello
答案: 【 s=hello

2、单选题:
​设有字符串s赋值如下:‎​String s = "hi,你好";‎​则s.length()的值为?‎
选项:
A: 4
B: 5
C: 3
D: 7
答案: 【 5

3、单选题:
‌以下哪个表达式被编译认为不合法?‌
选项:
A: String x="Hello"; int y=9; x+=y;
B: String x="Hello"; int y=9; if (x==y) { }
C: String x="Hello"; int y=9; x=x+y;
D: String x=null; int y=x.length();
答案: 【 String x="Hello"; int y=9; if (x==y) { }

4、单选题:
‎有如下程序段:‎‎public class ish{‎‎    public static void main(String[] args) {‎‎          String s="call me!";‎‎          System.out.print(s.charAt(s.length()-1));‎‎    }‎‎}‎
选项:
A: e
B: c
C: !
D: s
答案: 【 !

5、单选题:
‌设有下面两个赋值语句:‎‌a = Integer.parseInt("1024");‎‌b = Integer.valueOf("1024").intValue();‎‌不考虑赋值中的自动包装转换,你认为a,b最适合的数据类型是?‎
选项:
A: a是int类型变量,b是Integer类对象。
B: a是Integer类对象,b是int类型变量。
C: a和b都是Integer类对象并且它们的值相等。
D: a和b都是int类型变量并且它们的值相等。
答案: 【 a和b都是int类型变量并且它们的值相等。

6、单选题:
​以下程序的运行结果为?‍​class test{‍​    public static void main(String args[]) {‍​        String s = "Java是面向对象的语言,JavaScript是脚本语言";‍​        int k = -1;‍​        k = s.indexOf( '是', k + 1);‍​        System.out.print(k);‍​    }‍​}‍
选项:
A: -1
B: 4
C: 23
D: 5
答案: 【 4

7、多选题:
​设有一个字符串s赋值如下:‏​ String s="hello";‏​要获得字符串中的首个字符构成的子串可以用哪些方法?‏
选项:
A: s.startsWith()
B: s.substring(0,1)
C: ""+s.charAt(0)
D: String.valueOf(s.charAt(0))
答案: 【 s.substring(0,1);
""+s.charAt(0);
String.valueOf(s.charAt(0))

8、多选题:
‌要将整数25转换为二进制形式的数字串,可以用哪些方法?‌
选项:
A: Integer.toBinaryString(25)
B: Integer.toString(25,2)
C: Integer.toString(25)
D: Integer.parseInt("25",2)
答案: 【 Integer.toBinaryString(25);
Integer.toString(25,2)

9、多选题:
‎给出如下定义:‏‎String s = " Example "; ‏‎选出合法代码‏
选项:
A: s[3] = "x";
B: int i = s.length();
C: String t = "For " + s;
D: String shortS = s.trim();
答案: 【  int i = s.length(); ;
String t = "For " + s; ;
String shortS = s.trim();

10、多选题:
​设有如下代码 ‍​class StringTest {‍​ public static void main (String [] args){‍​ String a="Hello";‍​ StringBuffer c=new StringBuffer ("Hello");‍​ String b="Hello";‍​ StringBuffer d =new StringBuffer ("Hello");‍​ if (>>) {}‍​ }‍​} ‍​在>>位置替换为以下哪个条件为真? ‍
选项:
A: b.equals(a)
B: b==a
C: c==d
D: d.equals( c)
答案: 【 b.equals(a);
b==a

11、多选题:
‍假设ch为字符类型变量,要判断ch是否为数字字符,用那种方法?‌
选项:
A: ch>='0' && ch<='9'
B: ch-'0'>=0
C: Character.isDigit(ch)
D: 0< =ch<=9
答案: 【 ch>='0' && ch<='9';
Character.isDigit(ch)

12、填空题:
‎以下程序的运行结果为?‎public class Test5{‎   public static void main(String argv[]){‎      StringBuffer x = new StringBuffer("你好");‎      myMethod(x); ‎      System.out.print("x=" + x);‎   }‎   public static void  myMethod(StringBuffer s){‎      s.append(",Hi");‎   }‎‎}‎
答案: 【 x=你好,Hi

13、填空题:
‏写出以下程序运行结果​‏public class test {​‏   public static void main(String a[]){​‏          int x=12653;​‏         String m=""+x;​‏         StringBuffer b=new StringBuffer();​‏         for (int k=0; k < m.length(); k++) {​‏               b.insert(0,m.charAt(k));​‏         }​‏         System.out.print(b);​‏   }​‏}​
答案: 【 35621

14、填空题:
‎以下程序运行结果为?‏‎public class test {‏‎ public static void main(String args[]) { ‏‎ String s1 = "abc";‏‎ String s2 = new String("abc");‏‎ if(s1 == s2)‏‎ System.out.print(1);‏‎ else‏‎ System.out.print(2);‏‎ if(s1.equals(s2))‏‎ System.out.print(3);‏‎ else‏‎ System.out.print(4);‏‎ }‏‎}‏
答案: 【 23

异常处理

异常处理单元测验

1、单选题:
‎以下程序段执行时输入:java Test ‏‎则输出结果为( )。‏‎class Test {‏‎    public static void main(String args[ ]) {‏‎       System.out.println(args[0]);‏‎    }‏‎}‏
选项:
A: 无任何输出 
B: 产生数组访问越界异常
C: 输出 0
D: 输出 Test
答案: 【 产生数组访问越界异常

2、单选题:
​设有如下代码:‍​try { ‍​   tryThis(); ‍​   return; ‍​} catch (IOException x1) { ‍​     System.out.println("exception 1"); ‍​     return; ‍​} catch (Exception x2) { ‍​     System.out.println("exception 2"); ‍​     return; ‍​} finally { ‍​     System.out.println("finally");‍​} ‍​如果 tryThis() 抛出 NumberFormatException,则输出结果包括( )‍​‍
选项:
A: "exception 1"
B: "exception 1", 后跟 "finally" 
C: "exception 2", 后跟 "finally" 
D: "exception 2"
答案: 【 "exception 2", 后跟 "finally" 

3、单选题:
​设有如下代码段:‍​#1   String s = null;‍​#2   if ( s != null & s.length() > 0)‍​#3       System.out.println("s != null & s.length() > 0");‍​#4   if ( s != null && s.length() > 0)‍​#5       System.out.println("s != null & s.length() > 0");‍​#6   if ( s != null || s.length() > 0)‍​#7       System.out.println("s != null & s.length() > 0");‍​#8   if ( s != null | s.length() > 0)‍​#9       System.out.println("s != null | s.length() > 0");‍​将抛出空指针异常的行是( )。‍
选项:
A: 2、4
B: 6、8
C: 2、4、6、8
D: 2、6、8 
答案: 【 2、6、8 

4、多选题:
‌设有一个串s,和一个int型变量i,以下那条语句可能产生异常?‌
选项:
A:  if ((s !=null) && (  i ==s.length()))
B:  if ((s ==null) && (  i ==s.length())) 
C: if ((s !=null) || ( i ==s.length()))
D: if ((s ==null) || ( i ==s.length()))
答案: 【  if ((s ==null) && (  i ==s.length())) ;
if ((s !=null) || ( i ==s.length()))

5、多选题:
设有如下代码:‎ class Base{ ‎      public void amethod(int i) {  }‎  } ‎  public class Scope extends Base{‎     public static void main(String argv[]){‎     } ‎     //Method Here‎  }‎以下哪个方法可插入//Method 处?‎
选项:
A:  public void amethod(int i) throws Exception {}  
B:  public void amethod(int i)  { }
C: public void amethod(long i)  { }
D: public void amethod(String  i) { }
答案: 【  public void amethod(int i)  { };
public void amethod(long i)  { };
public void amethod(String  i) { }

6、多选题:
​关于try..catch..finally执行机制的描述,以下叙述那个正确?‏
选项:
A: 每个try 块必须至少跟一个catch块. 
B: 一个try 块可跟任意个finally块. 
C: 一个try块必须至少跟一个finally 或 catch块. 
D: 如果catch 和 finally块均有,则catch 必须先于finally. 
答案: 【 一个try块必须至少跟一个finally 或 catch块. ;
如果catch 和 finally块均有,则catch 必须先于finally. 

抽象类、接口及内嵌类

抽象类与接口测验

1、单选题:
‎以下程序的调试结果为( )。​‎p

剩余75%内容付费后可查看

发表评论

电子邮件地址不会被公开。 必填项已用*标注