常用数据类型处理类

常用数据类型处理测验

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、单选题:
​关于以下程序段,正确的说法是(             )‌​1.  String  s1="abc"+"def";‌​2.  String  s2=new  String(s1);‌​3.  if(s1==s2)‌​4.      System.out.println("= = succeeded");‌​5.  if (s1.equals(s2))‌​6.      System.out.println(".equals()  succeeded");‌
选项:
A: 行4与行6都将执行
B: 行4执行,行6不执行
C: 行6执行,行4不执行
D: 行4、行6都不执行
答案: 【 行6执行,行4不执行

8、单选题:
​如下代码:‍​  public class Quiz3_2{‍​    public static void main(String[] args){‍​      String a="Hello";‍​      String b="World!";‍​      f( a, b );‍​      System.out.println(a);‍​    }‍​    public static void f(String x, String y)  {‍​       x += y;‍​    }‍​  }‍​ 下述哪条叙述正确描述了程序编译和运行的行为?‍
选项:
A: 编译成功,输出为“Hello”
B: 编译成功,输出为“World!”
C: 编译成功,输出为“Hello World!”
D: 编译拒绝表达式x+=y, 因为不能改变一个String对象的值
答案: 【 编译成功,输出为“Hello”

9、单选题:
​如下代码:‎​  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);‎​   }‎​ }‎​ 下述哪条陈述正确描述了程序行为?‎
选项:
A: 输出为 true
B: 输出为 false
C: 输出为 0
D: 输出为 1
答案: 【 输出为 false

10、单选题:
‏调用以下类D和E的main()  方法的输出结果为?​‏class D { ​‏  public static void main(String[] args) { ​‏    String s1 = new String("hello"); ​‏    String s2 = new String("hello"); ​‏    if (s1.equals(s2)) ​‏       System.out.println("equal");​‏    else ​‏       System.out.println("not equal");​‏  }​‏} ​‏class E { ​‏   public static void main(String[] args) { ​‏     StringBuffer sb1 = new StringBuffer("hello"); ​‏     StringBuffer sb2 = new StringBuffer("hello"); ​‏     if (sb1.equals(sb2)) ​‏       System.out.println("equal");​‏     else ​‏       System.out.println("not equal");​‏  }​‏} ​
选项:
A: D: equal; E: equal 
B: D: not equal; E: not equal 
C: D: equal; E: not equal 
D: D: not equal; E: equal 
答案: 【 D: equal; E: not equal 

11、单选题:
‏以下哪个方法用来从字符串中获取一个字符?‍
选项:
A: indexOf(String str)
B: split(String str,char ch)
C: concat(String str)
D: charAt(int index) 
答案: 【 charAt(int index) 

12、多选题:
​设有一个字符串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))

13、多选题:
‌要将整数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)

14、多选题:
‌给出如下定义:‏‌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();

15、多选题:
‏设有如下代码 ‍‏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

16、多选题:
‌假设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)

17、填空题:
‏以下程序的运行结果为?‌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

18、填空题:
‌写出以下程序运行结果‎‌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

19、填空题:
​以下程序运行结果为?​​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

20、填空题:
‏以下代码的输出结果?‌‏public class Test{‌‏  public static void main(String argv[]){‌‏      String x="hello";‌‏      change(x);  ‌‏      System.out.println(x);‌‏  }‌‏  static void change(String m){‌‏      m=m+2;‌‏  }‌‏}‌
答案: 【 hello

21、填空题:
‌设有一个字符串s的内容为"welcome to China!",‍‌则, s.substring(3,8)的结果为?‍
答案: 【 come

异常处理

异常处理单元测验

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、单选题:
‍假设m()方法声明抛出IO异常,哪个写法合法?​
选项:
A: void m() throws IOException{ } 
B: void m() throw IOException{ } 
C: void m(void) throws IOException{ }
D: m() throws IOException{ } 
答案: 【 void m() throws IOException{ } 

5、单选题:
‏当2个实际参数分别为4和0时,以下方法调用的执行结果为:‌‏public void divide(int a, int b) {‌‏    try {‌‏      int c = a / b;‌‏     } catch (Exception e) {‌‏         System.out.print("Exception ");‌‏     } finally {‌‏       System.out.println("Finally");‌‏     }‌‏  }‌
选项:
A: 输出 Exception Finally 
B: 输出 Finally
C: 输出 Exception 
D: 无输出
答案: 【 输出 Exception Finally 

6、单选题:
‎下列关键字中用于明确抛出一个异常的是?‏
选项:
A: try
B: catch
C: throw 
D: finally 
答案: 【 throw 

7、多选题:
‌设有一个串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()))

8、多选题:
设有如下代码:‏ 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) { }

9、多选题:
​关于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. 

10、多选题:
​下列两个类分别定义在各自文件中?‍​ 1. public class Testl {‍​ 2. public float aMethod(float a, float b) throws‍​ 3.    IOException {...‍​ 4.    }‍​ 5.  }‍​‍​ 1. public class Test2 extends Testl {‍​ 2.‍​ 3.  }‍​在类Test2的第2行能插入以下哪个方法?‍
选项:
A: float aMethod(float a, float b) {...}
B: public int aMethod(int a, int b) throws Exception {...} 
C: public float aMethod(float a, float b) throws Exception {...}
D: public float aMethod(float p, float q) {...}
答案: 【 public int aMethod(int a, int b) throws Exception {...} ;
public float aMethod(float p, float q) {...}

11、多选题:
‎下面的代码:‎‎ class E1 extends Exception{ };‎‎ class

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

发表评论

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