本人由于一年多没用java,现在在搞.net,学校最近又推荐工作,给了一套java的考题,进行初选
请会做的帮个忙,做好后将答案以附件发给我 [email protected], 没把握的请不要勉强, 谢谢了一 选择题 (每题有1到多个选择。每题3分,共30分)1. 下面哪些是Java 的关键字。
① abstract ② sizeof ③ native ④ NULL ⑤ BOOLEAN
2.下面哪些是正确的实例化数组的代码。
① int a[10][10] = new int[ ][ ];
② int a[ ][ ] = new int[10][10];
③ int [ ][ ]a = new int[10][10];
④ int a = new int[10][10];3.Math.round(-11.5)等於多少?
① -11 ② -12 ③ -10 ④ 114.下面哪些class有继承自Collection接口
① List ② Set ③ Map ④ Vector5.switch(a), a能为下列那些类型
① byte ② integer ③ int ④ long6.请正确选择下面代码的执行结果?
label:
for( int i = 0; i < 2; i++ ){
for( int j = 0; j < 2; j++ ){
if( j == 1 ) continue label;
System.out.print( "i:" + i + " j:" + j );
}
}
① i:0 j:0
② i:0 j:1
③ i:0 j:2
④ i:1 j:0
⑤ i:1 j:1
⑥ i:1 j:27.请正确选择下面代码的执行结果
int x = 0;
int y;
int z = x + y;
System.out.println( "z:" + z );① 编译错误。
② 发生NullPointerException 例外。
③ 在控制台输出z: 0 。
④ 在控制台输出z: 。8.请正确选择下面代码在控制台的输出结果
class C{
static{ System.out.print("Hello!"); }
C(){ System.out.print("World!"); }
void x(){ System.out.print("Thank you"); }
}
class A{
public static void main( String args[ ] ){ C c = new C(); }
}
① Thank you ② World! ③ Hello!World! ④World!Hello!
9.请阅读下面代码。1)…5)是标志代码的编号。
1)String a = "Hello";
2)StringBuffer b = new StringBuffer( " There" );
3)StringBuffer c;
4)c = a + b;
5)System.out.println( "c=" + c );请正确选择上面代码的执行结果
① 输出Hello There。
② 在第4行因为无法重载操作符=而导致编译错误。
③ 在第4行因为无法重载操作符+而导致编译错误。
④ 在第5行因为无法重载操作符+而导致编译错误。
⑤ 在第5行因为参数类型不抑制而导致编译错误。10.请阅读下面代码
try{
发生例外(代码省略)
System.out.println("Sunday");
}catch( MyException e ){
System.out.println("Monday");
return;
}finally{
System.out.println("Tuesday");
}
请选择在控制台输出的内容
① Sunday ② Monday ③ Tuesday三 程序设计题(每题20分,共20分)
1) 请用JAVA设计实现一个数组排序的算法。
请会做的帮个忙,做好后将答案以附件发给我 [email protected], 没把握的请不要勉强, 谢谢了一 选择题 (每题有1到多个选择。每题3分,共30分)1. 下面哪些是Java 的关键字。
① abstract ② sizeof ③ native ④ NULL ⑤ BOOLEAN
2.下面哪些是正确的实例化数组的代码。
① int a[10][10] = new int[ ][ ];
② int a[ ][ ] = new int[10][10];
③ int [ ][ ]a = new int[10][10];
④ int a = new int[10][10];3.Math.round(-11.5)等於多少?
① -11 ② -12 ③ -10 ④ 114.下面哪些class有继承自Collection接口
① List ② Set ③ Map ④ Vector5.switch(a), a能为下列那些类型
① byte ② integer ③ int ④ long6.请正确选择下面代码的执行结果?
label:
for( int i = 0; i < 2; i++ ){
for( int j = 0; j < 2; j++ ){
if( j == 1 ) continue label;
System.out.print( "i:" + i + " j:" + j );
}
}
① i:0 j:0
② i:0 j:1
③ i:0 j:2
④ i:1 j:0
⑤ i:1 j:1
⑥ i:1 j:27.请正确选择下面代码的执行结果
int x = 0;
int y;
int z = x + y;
System.out.println( "z:" + z );① 编译错误。
② 发生NullPointerException 例外。
③ 在控制台输出z: 0 。
④ 在控制台输出z: 。8.请正确选择下面代码在控制台的输出结果
class C{
static{ System.out.print("Hello!"); }
C(){ System.out.print("World!"); }
void x(){ System.out.print("Thank you"); }
}
class A{
public static void main( String args[ ] ){ C c = new C(); }
}
① Thank you ② World! ③ Hello!World! ④World!Hello!
9.请阅读下面代码。1)…5)是标志代码的编号。
1)String a = "Hello";
2)StringBuffer b = new StringBuffer( " There" );
3)StringBuffer c;
4)c = a + b;
5)System.out.println( "c=" + c );请正确选择上面代码的执行结果
① 输出Hello There。
② 在第4行因为无法重载操作符=而导致编译错误。
③ 在第4行因为无法重载操作符+而导致编译错误。
④ 在第5行因为无法重载操作符+而导致编译错误。
⑤ 在第5行因为参数类型不抑制而导致编译错误。10.请阅读下面代码
try{
发生例外(代码省略)
System.out.println("Sunday");
}catch( MyException e ){
System.out.println("Monday");
return;
}finally{
System.out.println("Tuesday");
}
请选择在控制台输出的内容
① Sunday ② Monday ③ Tuesday三 程序设计题(每题20分,共20分)
1) 请用JAVA设计实现一个数组排序的算法。
2. int a[][] = new int[10][10]
3. pass
4. 模糊,好像是Vector吧
5. int
6. pass
7. 编译错误
8. class A不是public,main应该不会执行吧。
非选的话,应该是:Hello World
9. 第4行无法重载操作符+错误
10. Monday三,pass
4 4 (因为1,2是接口而不是类)
6 1, 4 (已测试)
public class BubbleSort{ /**
* Method sortArray
* 将数组转化成字符串
* @param array[]
* @return result
*/
static String sortArray(int[] array){
String result = "";
for(int i=0; i<array.length; i++){
result += array[i]+" ";
}
return result;
} /**
* Method bubbleSort
* 将数组排序
* @param array[]
* @return array
*/
static int[] bubbleSort(int[] array){
int t = 0;
/*
*原理: 每次将比较后的最大值放入数组的最后
* 并在下次比较中除去最大值进行比较
*/
for(int i=0; i<array.length; i++){
for(int j=0; j<array.length-i-1; j++){
if(array[j]>array[j+1]){
t = array[j];
array[j] = array[j+1];
array[j+1] = t;
}
}
}
return array;
} public static void main(String[] args){
int[] arr = {12,43,23,56,8,22};
System.out.println("Before: "+sortArray(arr));
//调用排序方法
arr = bubbleSort(arr);
System.out.println("After: "+sortArray(arr));
}
}
刚写的,已经经过测试了,楼主可以放心使用~~~~
①List ② Set ③ Map ④ VectorList、Set和Vector都继承Collection。但是List和Set是接口,只有Vector是类。所以正确答案应该是4。你自己看看“API Spec”。