在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。
1.下述字符组合不能作为Java程序标识符的是( D ) A.Aa12 B.大x C.y小
D.5x
2. 下列字符组合不能作为Java整型常量的是( A ) A. 078 C. 5000
B. 0x3ACB D. 0x3ABC
3.下面供选字符序列中,不属于...Java语言关键字的是( C ) A.goto C.false
B.null D.native
4.在下述字符串中,不属于...Java语言关键字的是 ( C) A.float C.java
B.new D.return
5.Java语言中数值数据的类型能自动转换,按照从左到右的转换次序为 (B ) A. byte→int→short→long→float→double B. byte→short→int→long→float→double C. byte→short→int→float→long→double D. short→byte→int→long→float→double 6. 指出正确的表达式 C A byte=128; B Boolean=null; C long l=0xfffL; D double=0.9239d;
7. 指出下列程序运行的结果B public class Example{
String str=new String(\"good\"); char[]ch={'a','b','c'};
public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+\" and \"); Sytem.out.print(ex.ch); }
public void change(String str,char ch[]){ str=\"test ok\"; ch[0]='g'; } }
A good and abc B good and gbc C test ok and abc D test ok and gbc
8.以下程序代码的输出的结果是( A )int x=53;
System. out. println(1.0+x/2); A.27.0 B.27.5 C.1.026
D.1.026.5
9.以下程序代码的输出结果是( A )
int x=73;System.out.println(x>>1);
A.36 C.37
10. 给出下面代码: A public class Person{
static int arr[] = new int[10]; public static void main(String a[]) {
System.out.println(arr[1]); } }
那个语句是正确的? A 编译时将产生错误;
B 编译时正确,运行时将产生错误; C 输出零; D 输出空。
11.以下程序代码的输出结果是( B ) int x = 10; while (x > 7)
{ System.out.print(\"*\"); x--;}
B.36.5 D.true
A.** B.*** C.* D.****
12.以下是关于字符串运算的代码,执行该代码段的输出结果是( D )
String s=″0123456789″,sl,s2;
sl=s.substring(2);s2=s.substring(2,5);System.out.println(s1+s2); A.0122345 C.012234 13.设有以下代码: String s l=\"123\"; String s2=\"123\";
String s3=new String(\"123\"); 则表达式s1==s2和s1==s3的值分别是(C) A.true,true C.true,false
B.false,false D.false,true
B.234567892345 D.23456789234
14.在下述Java语言语句中,错误的创建数组的方法是 ( D ) ..A.int intArray [ ]; intArray=new int[5]; B.int intArray [ ]=new int[5]; C.int [ ] intArray ={1,2,3,4,5}; D.int intArray [5]={1,2,3,4.5};
15.参照以下Java代码,以下四个叙述中最确切的是( B ) class A{ int x; static int y;
void fac(String s){Syatem. out. println("字符串:"+s);} }
A.x、y和s都是成员变量
B.x是实例变量、y是类变量、s是局部变量 C.x和y是实例变量、s是参数 D.x、y和s都是实例变量 16.下列代码哪几行会出错: C 1) public void modify() { 2) int I, j, k; 3) I = 100; 4) while ( I > 0 ) {
5) j = I * 2;
6) System.out.println (\" The value of j is \" + j ); 7) k = k + 1; 8) I--; 9) } 10) } A line 4 B line 6 C line 7 D line 8
17.在以下供选择的概念中,不属于面向对象语言概念的是 ( B ) ...A.消息 C.继承
B.模块 D.多态性
18.需要分析字符串,并将字符串分解成可被独立使用的单词,可使用java. util包中的类是( C ) A.String B.StringBuffer C.StringTokenizer
D.stringTokenizer
19.程序如果要按行输入输出文件的字符流,最合理的方法是采用( A ) A.BufferedReader类和BufferedWriter类 B.InputStream类和OutputStream类 C.FileReader类和FileWriter类 D.File_Reader类和File_Writer类
20.Java语言中,在类定义时用final关键字修饰,是指这个类( A ) A.不能被继承
C.能被别的程序自由调用
B.在子类的方法中不能被调用 D.不能被子类的方法覆盖
21.在以下供选择的方法中,不能用于文件随机访问的方法是( C ) ..A.readChar() C.readInteger()
B.readLong() D.writeChars()
22.某程序利用网址参数创建URL对象url,接着希望利用对象url获得URLConnection对象,则这个url
对象要调用的方法是( D ) A.connection() C.getConnection()
二、多项选择
23.执行下列代码后,哪个结论是正确的 String[] s=new String[10];D A s[10] 为 \"\"; B s[9] 为 null; C s[0] 为 未定义
B.URLConnection() D.openConnection()
D s.length 为10
24.下面的表达式哪个是正确的? AD A String s=\"你好\";int i=3; s+=i;
B String s=\"你好\";int i=3; if(i==s){ s+=i}; C String s=\"你好\";int i=3; s=i+s; D String s=\"你好\";int i=3; s=i+;
E. String s=null; int i=(s!=null)&&(s.length>0)?s.length():0; 25.选出合理的标识符 A A _sys1_lll B 2mail C $change D class
26.指出正确的表达式 ABD A double a=1.0;
B Double a=new Double(1.0); C byte a = 340; D Byte a = 120;
二、填空题(本大题共10小题,每小题2分,共20分)
请在每小题的空格中填上正确答案。错填、不填均无分。
27.用条件运算符构造一个表达式:goal等于10时,表达式的值为“对了!”,否则,表达式的值为“错了!”。这
个
表
达
式
是
_________。
28.类是对一组相同对象的描述,类概括了同类对象的共有性质:(数据(属性)和方法(函数))。 29.设有数组a和b的定义如下: int[]a={1,2,3};int[]b={4,5,6} „„
执行以下代码“a=b;”,除了完成赋值操作之外,引起系统额外要做的工作是(回收内存)。 30.Java程序的源文件的扩展名是___ class______。
31.构造一个Java表达式:y/x>5,并且x!=0。这个表达式是(y/x>5 && x!=0)。 32.在类声明之前用(final)修饰,声明类是不能被再继承的类,即它不能再有子类。 33.设有字符串定义: String s=\"ABCDABCD\";
则表达式s.indexOf(\"B\")的值是______ 1___。
34.为普通的8位字节流文件读和写操作提供支持的类是__( InputStream OutputStream)。
35.一个应用程序必须在某个类中定义的方法是_ main()_____。 36.在面向对象语言中,对象之间的交互通过____相互发送消息__实现。
37.设有两个字符串对象str1和str2,则表达式“strl==str2”的意义是判别字符串strl和str2__是否引用同一
个对象____。
38.Java的编译程序先将Java源程序翻译成与机器无关的__字节码________。 39.表达式¨23 & 18’’的值是___2318_______。
40.如果类A某个成员变量的类型是类B,则类A和类B之间是__ Has-a _关系。 41.Java语言提供了两个用于处理字符串的类,它们是____ String\\StringBuffer ______。 42.执行下列代码后的结果是什么? int x,a=2,b=3,c=4; x=++a+b++ .+c++; 11
43. 包包含了Collection的接口和类的API
44.下列程序中构造了一个SET并且调用其方法add(),输出结果是 public class A{
public int hashCode(){return 1;}
public Boolean equals(Object b){return true}
public static void main(String args[]){ Set set=new HashSet(); set.add(new A()); set.add(new A()); set.add(new A());
System.out.println(set.size()); } }
45.下列程序的运行结果是
三、简答题(本大题共6小题,每小题3分class A{ class Dog{
private String name; private int age; public int step; Dog(String s,int a) { name=s; age=a; step=0; }
public void run(Dog fast) {
fast.step++; } }
public static void main (String args[]) {
A a=new A();
Dog d=a.new Dog(\"Tom\ d.step=25; d.run(d);
System.out.println(d.step); } }
,共18分)
46. 请写出表示条件“x=2与y=3有且只有一个成立”的Java表达式”。 (x=2)!=(y=3)或(x=2&&
y!=3)||(x!=2&&y!=3)
47. 请写出表示year年是闰年的Java表达式。闰年的条件是:每4年一个闰年,但每100年少一个闰年,每400年又增加一个闰年。(year%4= =0) && (year%4!=0)||(year%400= =0)
48. 请写出实现计算y=|x|的if语句。if(x>=0)y=x; elsey=-x;
49. 以下代码定义了一个类,请指出其中三条不合法的代码行(行号参见注释)。4,5,6行错误
class Test22{
float u;static float v;
//1 //2
static void setUV(boolean f){ //3
u=fac1(f); v=fac2(!f);}
//4 //5
static float facl(boolean f){return f?u:v;} //6 float fac2(boolean f){return f?v:u;} //7
} //8
50.请写出一段if语句,判断一个整数n是否为偶数。如果是偶数,输出“Yes.”;否则,输出“No.”。
If(n%2==0){System.out.println(“Yes”);}els{System.out.println(“No”);}
四、程序填空题(本大题共5小题,每空2分,共20分)
51.方法int maxDigit(int n)的功能是找出十进制整数n各位中最大的一位数字。例如,n=23765,该方法的返回值是7。
static int maxDigit(int n){ int c=0,d; while(n>0){ d=_ n%10______; if(d>c) c=d; n/=10; }
___ return c _____; }
52.方法int sigmaDigit(int n)的功能是求出十进制整数n的各位数字之和。例如,n=1234,该方法的返回值是10。
static int sigmaDigit( int n ) { int sum = 0, d; while( n > 0 ){ d=n% 10;
_ sum+=d ________; n/= 10; }
return sum ;
}
53.方法int sigmaEvenNum(int[]a)的功能是求已知数组中偶数的个数。
static int sigmaEvenNum(int []a){
int s =0;
for ( int i=0;______;i++ ) {
if(______) s++;
} return s; }
54.方法void moveOddForword(int a[ ])的功能是将数组中的所有奇数移到所有偶数之前。 void moveOddForword(int a[]){
for(int i=0, odd=0;_ i 五、程序分析题(本大题共5小题,每小题4分,共20分) 55.阅读下列程序,请写出该程序的输出结果。p1.x=13 class A { int x, y; A(int a, int b) { x= a; y= b; } } public class sample { public static void main(String args[]) { A pl, p2; p2 = new A(12, 15); p1 = p2; p2.x++; System.out.println(\"p1.x=\" + p1 .x); } } 56.阅读下列程序,请写出调用pascal(4)的输出结果。 1 1 1 1 2 1 1 3 3 1 static void pascal(int n) { int pas[]; pas = new int[n]; pas[0] = 1; System.out.println(pas[0]); for (int i = 2; i <= n; i++) { /* 由存储在pas中的原来内容生成新内容*/ pas[i - l] =1; for (int j = i- 2;j > 0; j--) pas[j] = pas[j] + pas[j - 1 ]; for (int j = 0; j < i; j++) System.out.print(pas[j] +\" \"); System.out.println(); } 57.阅读下列程序,请写出该程序的输出结果。5671112 class Test33 { static void s (int b[ ], int k) { int i, j, t; for(i = 1;i< k; i++) { for(t = b[i], j = i-1; j >= 0 && t < b[j]; j--) b[j+l] = b[j]; b[j+ 1 ] = t; } } public static void main(String []args){ int i, a[] = {6, 12, 7, 11, 5 }; s(a, 5); for(i = 0;i< a.length; i++) System.out.print(a[i]+\" \"); System. out. Println(); } } 六、程序设计题(本大题共2小题,每小题6分,共12分) 58.编写一个方法halfArray(),要求该方法有一个元素类型为int的数组参数,方法返回一个新数组,新数组的长度与参数数组的长度相同,而新数组元素的值是参数数组各元素的一半。 int [] halfArray(int [] a){(1分) int [] b=new int[a.length];(2分) for(int k=0;k<a.length;k++){(2分) b[k]=a[k]/2; } return b;(1分) } 59.编写方法int searchMaxNumIndex(int[]a),寻找已知数组中最大数的下标并返回。 int searchMaxNumIndex(int[]a){ int i,maxIndex;(1分) for(i=maxIndex=0;i } return maxIndex;(1分) } 60.请编写方法void strReverse(String str),该方法的功能是输出一个新字符串,新字符串字符排列顺序与原字符串str的字符排列顺序相反。例如,strReverse(″ABCD″) 所输出的结果是″DCBA″。请使用字符串与字节数组的相互转换方法进行设计。 public static void strReverse(String str){ byte[] s=str.getBytes(); String t=\"\"; for(int i=s.length-1;i>=0;i--){ t+=(char)s[i]; } System.out.println(t); } 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务