Java基础-结课测试

1、单选

下面的方法,当输入为2的时候返回值是多少

 1 public int getValue(int i) {
 2 
 3          int result = 0;
 4 
 5          switch (i) { 
 6 
 7             case 1: 
 8 
 9                 result = result + i; 
10 
11             case 2: 
12 
13                 result = result + i  * 2; 
14 
15             case 3: 
16 
17                 result = result + i  * 3; 
18 
19         } 
20 
21         return result; 
22 
23  }
View Code
  • A.6
  • B.2
  • C.0
  • D.10

 

给出下面代码,关于该程序以下哪个说法是正确的

public class Person{  

     static int arr[] = new int[5]; 

     public static void main(String a[]) {  

          System.out.println(arr[0]);

     }   

}
View Code
  • A.编译时将产生错误
  • B.输出空
  • C.编译时正确,运行时将产生错误
  • D.输出0

 

list是一个ArrayList的对象,哪个选项的代码填写到//todo delete处,可以在Iterator遍历的过程中正确并安全的删除一个list中保存的对象?

 1         Iterator it = list.iterator();
 2 
 3         int index = 0;
 4 
 5         while (it.hasNext()){ 
 6 
 7               Object obj = it.next(); 
 8 
 9               if (needDelete(obj)) { //needDelete返回boolean,决定是否要删除
10 
11                    //todo delete
12 
13                } 
14 
15               index ++;
16 
17         }
View Cod
  • A.it.remove();
  • B.list.remove(it.next());
  • C.list.remove(index);
  • D.list.remove(obj);

  相关文章:使用Iterator的remove方法删除元素

转载于:https://www.cnblogs.com/windJcoder/p/5434448.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值