Java程序设计题库.pdf
《Java程序设计题库.pdf》由会员分享,可在线阅读,更多相关《Java程序设计题库.pdf(88页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Java程序设计-题库1、下面哪个是对字符串si的不正确定义().A、S trin g sl=abcd;B、S trin g si;C、S trin g sl=,abcd O;D、S trin g sl=abcd”;答案:C2、执行下列代码后,哪个结论是正确的().S trin g口 s=n ewS trin gEl O ;A、s 10 为 n ul 1;B、s 9 为 0;C、s 0 为未知数;D、s.l en gth 为 10答案:D3、应用程序的m ain 方法中有以下语句,则输出的结果是()。S trin gsl=0.5,s2=12;do ubl e x=Do ubl e.parseD
2、o ubl e(sl);in ty=I n teger.parsel n t(s2);S ystem,o ut.prin tin(y+x);A、12.5B、120.5C、12D、“12.5”答案:A4、S ystem.o ut.prin t(+2)打印到屏幕的结果是()A、3B、12C、1+2D、4答案:B5、在 Java的类的体系结构中,所有类的根类是()。A、Fram eB、O bjectC、S trin gD cl ass答案:B6、下面可以产生大于等于0,小于10 的随机整数的Java语句是()。A、M ath,ran do m()*10B、R an do m,n extl n t(1
3、0)C、(in t)M ath.ran do m()*10D、(in t)(M ath,ran do m()*10)答案:D7、S trin g类中获取字符串长度的方法是()。A s l en gth()B、l en gthC、to S trin g()Ds equal s()答案:A8、in t in dex=*I l o ve Java,java is very po werful!”.in dexO f(java);语句执行后的结果是()。A、12B、11C、10D、13答案:A9、S trin g s=山东信息职业技术学院.repl aceA l l(职业,);语句执行后字符串s 的值
4、是()。A、山东信息职业技术学院B、山东信息技术学院C、山东信息*技术学院D、山东信息技术学院答案:B10、比较密码S trin g pwl;和确认密码S trin g pw2;是否一致的方法是()。A、pwl=pw2B、pwl=pw2C、pwl.equal s(pw2)D、pwl.l en gth()=pw2.l en gth()答案:C11、可以把in t x=123;中x 的值赋给S trin g类型的变量s 的是()。A、s=x;B、s=(S trin g)x;C、s=I n teger.parsel n t(x);D、s=S trin g.val ueO f(x);答案:D12、可以
5、把S trin g s=123;中s 的值转换成整型数据的办法是()。A、I n teger,parsel n t(s)B、(in t)sC、S trin g.val ueO f(s)D、Do ubl e.parserDo ubl e(s)答案:A13、设字符串 s=Hel l o W o rl d”,计算表达式 s.in dexO f(el l o)的值_ _ _ _答案:1解析:14、下列程序输出结果为-1public class test(public static void main(String args)String s=I am a string!”int n=s.length(
6、);char c=s.charAt(7);System,out.print(n+,);System,out.println(c);)答案:14,s解析:15、Java语言中用于字符串处理的类只有String。答案:错误16、可以通过s.length来获取字符串s 的长度。答案:错误17、产生一个0 T 0 的随机整数的方法是:int x=(int)M ath,random()*10.答案:错误18、借助于集合框架ArrayL ist和泛型存储某班的名单(李萌萌,张航,王梅,李勇),并查找“张航”是否存在,将查找结果进行输出显示。提示:只存放姓名,使用String类即可。答案:解析:19、抛出异
7、常时,应该使用的子句是()A、thro wB、catchC、fin al l yD thro ws答案:A20、对于try catch子句的排列方式,正确的一项是()A、子类异常在前,父类异常在后B、父类异常在前,子类异常在后C、只能有子类异常D、父类异常与子类异常不能同时出现答案:A21、下列关于try、catch和 fin al l y的表述中,错误的是()A、try语句块后必须紧跟catch语句块B、catch语句块必须紧跟在try语句块后C、可以有try但无catchD、可以有try但无fin al l y答案:C22、如果一个程序段中有多个catch,则程序会按如下哪种情况执行?()
8、A、找到合适的异常类型后继续执行后面的c a t c hB、找到每个符合条件的c a t c h 都执行一次C、找到合适的异常类型后就不再执行后面的c a t c hD、对每个c a t c h 都执行一次答案:C23、一个t r y 代码段后必须跟 1 代码段,2代码段可以没有。答案:c a t c hfinally24、异常处理机制可以允许根据具体的情况选择在何处处理异常,可以在1捕获并处理,也可以用throws子句把它交给_2去处理。答案:catch部分;调用方法;25、异常处理中总是将可能产生异常的语句放在try块中,用catch子句去处理异常,而且一个try块之后只能对应一个catc
9、h语句。()答案:错误26、java异常处理中可以使用多个catch子句,此时应将高级别异常类的catch子句放在前面。()答案:错误27、当一个方法在运行过程中产生一个异常,则这个方法会终止,但是整个程序不一定终止运行。()答案:正确28、捕获异常try语句后面通常跟有一个或多个catch。方法用来处理try块内生成的异常事件。()答案:正确29、使 用try-catch-finally语句只能捕获一个异常。()答案:错误30、try-catch语句不可以嵌套使用。()答案:错误31、lOException异常是非运行时异常,必须在程序中抛弃或捕获。()答案:正确32、编写程序实现,接收用户
10、输入的任意两个整数,输出较大者。答案:p u b l i c c l a s s T e s t Y M p u b l i c s t a t i c v o i d m a i n(S t r i n g a r g s)i n t y e a r,m o n t h;S y s t e m.o u t.p r i n t i n (”请输入年份、月份);S c a n n e r i n=n e w S c a n n e r(S y s t e m,i n);y e a r=i n.n e x t l n t();m o n t h=i n.n e x t l n t ();i n t
11、 d a y=30;i f(m o n t h=l|m o n t h=3|m o n t h=5|m o n t h=7|m o n t h=8|m o n t h=1 0|(m o n t h=1 2)d a y=31;e l s e i f (m o n t h=2)是否闰年i f(y e a r%4=0&y e a r%1 0 0!=0|y e a r%40 0=0)d a y=29;e l s e d a y=28;)S y s t e m,o u t.p r i n t l n(d a y);)解析:33、找素数素数就是不能再进行等分的整数。比如而9 不是素数,因为它可以平分为 3
12、 等份。一般认为最小的素数是2,接着是3,5,.请接收用户输入的一个整数,判断其是否素数。答案:p u b l i c c l a s s T 1 8 /检查是否素数p u b l i c s t a t i c b o o l e a n c h e c k(i n t n)f o r(i n t i=2;i*i =n;i+)i f (n%i=0)r e t u r n f a l s e;)r e t u r n t r u e;p u b l i c s t a t i c v o i d m a i n(S t r i n g a r g s)i n t n =1;i n t i =3
13、;w h i l e(n,z+i);i+;e l s e i+;第1 0 0个素数是5 4134、借用数学类的随机数生成方法,随机生成一个由4个数字构成验证码。方法原型如下:p u b l i c s t a t i c d o u b l e r a n d o m()返回带正号的d o u b l e值,该值大于等于00且小于l.O o答案:P u b l ic s t a t ic v o id m a in(St r in g a r gs)in t a r r =n e w in t 31;f o r(in t i=1;i =30;+i)a r r i =(in t)i*i*i;)f
14、 o r(in t a =1;a =27;+a)f o r (in t b =a+1;b =28;+b)f o r (in t c =b+1;c =29;+c)f o r (in t d =c+1;d D a a=156答案:B解析:36、阅读下列代码p u b l ic c l a s s Te s t St r in g s=O n e Wo r l d O n e Dr e a m;p u b l ic s t a t ic v o id m a in(St r in g a r gs )Sy s t e m,o u t.p r in t in (s);)其运行结果是 OA、A、a r
15、gsB、B O n e Wo r l d O n e Dr e a mC、C sD、D、编译时出错答案:D解析:37、下 列 程 序 的 运 行 结 果 是 D a b c答案:D解析:38、下列程序的运行结果是 op u b l ic c l a s s Te s t p u b l ic s t a t ic v o id m a in(St r in g a r gs)in t p e r c e n t=10;t r ip l e Va l u e(p e r c e n t);Sy s t e m,o u t.p r in t I n(p e r c e n t);)p u b l
16、ic s t a t ic v o id t r ip l e Va l u e(in t x)x=3*x;)A、A、40B、B、30C、C、20D、D、10答案:D解析:39、若有语句in t a=2,b=2;则下列表达式中值为4 的是A A、(+a)*(+b)B B、(a+)*(b+)C、C、(a+)*(+b)D、D、(+a)*(b+)答案:B40、关于下列代码的描述中,正确的是 o p u b l ic c l a s s P e r s o n in t a r r=n e w in t 9 ;p u b l ic s t a t ic v o id m a in(St r in g
17、a r gs)Sy s t e m,o u t.p r in t in(a r r 10);A、A、编译时将产生错误B、B、编译时正确,运行时将产生错误C、C、输出0D、D、输出 n u l l答案:A41、下列程序执行后的结果是 op u b l ic c l a s s Te s t p u b l ic s t a t ic v o id m a in(St r in g a r gs)in t a=n e w in t 10;in t s=0;f o r(in t i=0;i 10;i+)a i=i;)t r y(f o r(in t i=0;i D Exception 1 No ex
18、ception答案:A解析:42、下列程序的运行结果是 o public class M yTest public staticvoid main(String args)int i=0,j=0;for(j=l;j0)System,out.printin(Hello.);else if(x-3)System,out.printin(Nice to meet you!);else System,out.println(How are you?);若打印字符串How are you?,则 x 的 取 值 范 围 是。A、A、x0B、B、x-3C、C、x=-3D、D x -3答案:C解析:44、请阅
19、读下面程序p u b l ic c l a s s F o r L o o p St a t e m e n t p u b l ic s t a t ic v o id m a in(St r in g a r gs)in t i,j;f o r(i=l;i 5;i+)/i 循环f o r(j=l;j 2)?4:5);其运行结果是 oA、A、2B、B、3C、C、4D、D、5答案:C50、阅读下面程序 p u b l ic c l a s s Te s t 4p u b l ic s t a t ic v o id m a in(St r in g a r gs )in t i=10,j=3;
20、f l o a t m=213.5f ,n=4.O f;Sy s t e m,o u t.p r in t in(i%j);Sy s t e m,o u t.p r in t in(m%n);程序运行的结果是 oA、A、1.0 和 1.5B、B、1 和 1.5C、C、1.0 和 2.5D、D、1 和 2.5答案:B51、给出下面的代码 if (x 0)Sy s t e m,o u t.p r in t l n(*f ir s t*);e l s e if(x -3)Sy s t e m,o u t.p r in t in(s e c o n d);e l s e Sy s t e m.o u
21、t.p r in t in(*t hir dz,);x的取值在 范围内时将打印字符串s e c o n d 。A、A、x 0B、B x _3C、C、x =-3D、D、x -3答案:D52、阅读下列代码p u b l ic c l a s s p u b l ic s t a t ic v o id m a in(St r in g a r gs )d o u b l e d=12.3;De c r e m e n t e r d e c=n e w De c r e m e n t e r();d e c.d e c r e m e n t(d);Sy s t e m,o u t.p r in
22、 t l n(d);)c l a s s De c r e m e n t e r p u b l ic v o id d e c r e m e n t(d o u b l e d e c M e)d e c M e=d e c M e-l.0;)代码执行后输出结果是 oA、A、12.3B、B、11.3C、C、13.3D、D、-1.0答案:A解析:53、s w it c h(m)c a s e 0:Sy s t e m,o u t.p r in t I n(Co n d it io n 0);c a s e 1:Sy s t e m,o u t.p r in t I n(Co n d it
23、io n 1);c a s e 2:Sy s t e m,o u t.p r in t in(Co n d it io n 2);c a s e 3:Sy s t e m,o u t.p r in t I n(Co n d it io n 3);b r e a k;d e f a u l t:Sy s t e m,o u t.p r in t l n C O t he r Co n d it io n);)当m的值为 时,下列哪个选项中的所有值都能引起Co n d it io n 1”的输出。A、A、0,1B、B、1,2C、C、2,3D、D、3,4答案:A解析:54、阅读下面程序 p u b
24、l ic c l a s s Te s t 3p u b l ic s t a t ic v o id m a in(St r in g a r gs )in t x=3,y=4,z=5;St r in g s=x y z;Sy s t e m,o u t.p r in t in(s+x+y+z);程序运行的结果是 oA、A、x y z l 2B、B、x y z 345C、C、x y z x y zD、D、12x y z答案:B55、下列程序段的输出结果是 o in t d a t a =0;c ha r k=a,p=f;d a t a=p-k;Sy s t e m,o u t.p r in
25、t l n(d a t a);A、A、0B、B、aC、C、fD、D、5答案:D56、下 列 程 序 的 运 行 结 果 是 c l a s s Sha p e p u b l ic Sha p e()Sy s t e m,o u t.p r in t(Sha p e);)c l a s s Cir c l e e x t e n d s Sha p e p u b l ic Cir c l e()Sy s t e m,o u t.p r in t(Cir c l e);)p u b l ic c l a s s Te s t p u b l ic s t a t ic v o id m a i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 程序设计 题库
限制150内