设有一个数组列表x,定义如下: ArrayList[String] x = new ArrayList[String]() {{add("he");add("i");add("you");}};以下哪些办法可以输出数组列表x中的所有元素?
A: for(String a:x) System.out.print(a+",");
B: for (int i=0;iC: System.out.print(x);
D: x.forEach(e->System.out.print(e+","));
A: for(String a:x) System.out.print(a+",");
B: for (int i=0;i
D: x.forEach(e->System.out.print(e+","));
举一反三
- 下列选项中,循环会无限执行的是______。 A: int i = 1 ; while ( i < 10) System .out .print( “ ” + i) ; B: for( int i = 1 ; i < 10 ;i ++) System .out .print( “ ” + i); C: for( int i = 10 ; i > 0 ;i --) System .out .print( “ ” + i); D: int i = 1 ; while (true) { System .out .print( “ ” + i); i ++ ; if ( i > 5) break ;
- 使用数组x输出10个1-100之间的随机整数(包括1和100),下列命令中正确的是:( ) A: Dim x(9) As Integer For i = 1 To UBound(x) x(i) = Int(Rnd() * 100 + 1) Print x(i); Next B: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Rnd(10) Print x(i); Next C: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Int(Rnd() * 100 ) Print x(i); Next D: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Int(Rnd() * 100 + 1) Print x(i); Next
- 设有定义语句int x[6]={2,4,6,8,5,7},*p=x,i;要求依次输出x数组6个元素的值,不能完成此操作的语句是( )。 A: for(i=0;i<6;i++) print("%2d",*(p++)); B: for(i=0;i<6;i++) print("%2d",*(p+i)); C: for(i=0;i<6;i++) print("%2d",*p++); D: for(i=0;i<6;i++) print("%2d",*(p)++);
- 依次输入三个整数放在一个列表中,请把这三个数由小到大输出。m=[]for i in range(3):x=int(input("x="))_____________________m.sort ()for i in m:print(i,end="" )
- 初始了如下二维数组,( )能够遍历该二维数组。 int [ ][ ] arr={{3,4,5},{7,8,2},{1},{6,2,8}}; A: for(int i=0;i B: for(int i=0;i C: for(int i=0;i D: for(int list:arr) for(int x:list) System.out.println(x); E: for(int[ ] list:arr) for(int x:list) System.out.println(x);