Java基础练习题-.pdf





《Java基础练习题-.pdf》由会员分享,可在线阅读,更多相关《Java基础练习题-.pdf(34页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、基础练习题一、简单 Java 程序调试1)以下哪个是Java应用程序main 方法的有效定义?A.public static void main();B.public static void main(String args);C.public static void main(String args);D.public static void main(Graphics g);E.public static boolean main(String a);2)编译和运行以下代码的结果为:public class MyMain public static void main(String arg
2、v)System.out.println(Hello cruel world);A编译错误;B运行输出Hello cruel world;C编译无错,但运行时指示没有定义构造方法。D编译无错,但运行时指示没有正确定义main 方法。3)下列选项中不属于Java 虚拟机的执行特点的一项是:A异常处理B多线程C动态链接D简单易学4)不属于 Java 语言特点的一项是:A分布式B.安全性C.编译执行D.面向对象5)以下程序的运行结果为:public class Test public static void main(String argv)System.out.println(x=+5);A.5
3、B.x=5 C.x=+5 D.x=5 6)以下程序的运行结果为:public class Test public static void main(String argv)System.out.println(good+morning);A.goodmorning B.good+morning C.good morning D.good+morning 二、Java符号与表达式1)现有一个int 类型的整数和一个double 类型的数进行加法运算,则得到的结果类型为:A int 类型B.double 类型C.float 类型D.long 类型2)下面程序段的输出结果是:int a=2;Syst
4、em.out.print(a+);System.out.print(a);System.out.print(+a);A333 B334 C 234 D233 3)以下代码的输出结果?public class Test int x=3;public static void main(String argv)int x=012;System.out.println(x);A12 B012 C 10 D3 4)下列定义语句正确的是:Achar c=n;Bint i=12;Cfloat f=2.8;Dboolean b=null;5)检查如下代码:public class Quiz2_l public
5、 static void main(String args)int a=8;int b=-8;System.out.print(a1);下列哪条语句正确描述了程序在编译和运行时的行为?A编译成功,输出为“32,-4”B.编译成功,输出为“16,4”C.编译成功,输出为“32,2147483644”D.编译成功,输出为“16,2147483644”E.编泽器拒绝表达式b,因为不能对一个负数应用操作符6)以下代码的输出结果为:System.out.println(+2+3);System.out.println(2+3);System.out.println(2+3+);System.out.pr
6、intln(2+3);A第 3 行出现编译错误B输出 23,5,5 和 23.C输出 5,5,5 和 23.D输出23,5,23 和 23.7)设有如下变量说明:byte myByte;int myInt;long myLong;char myChar;float myFloat;double myDouble;以下赋值语句哪个需要强制转换。AmyInt=myByte;BmyInt=myLong;CmyByte=3;DmyInt=myChar;EmyFloat=myDouble;FmyFloat=3;GmyDouble=3.0;8)考虑如下两语句:1.boolean passingScore=
7、false&grade=70;2.boolean passingScore=false&grade=70;表达式 grade=70 在什么地方被计算A在1 和 2 中均计算B在1 和 2 中均未计算C在 1 中计算,在2 中未计算D在 2 中计算,在1 中未计算E非法,因为false 应写FALSE 9)设有一个整数x 其二进制值为10011100(用 1 字节表示),则执行如下语句后z 的二进制值为:int y=1 c?a:c;d=d2b?d:b;System.out.println(b);A2 B 3 C 5 D7 三、分支程序设计1)下列语句片段的结果为int result;int a=
8、17,b=6;result=(a%b4)?a%b:a/b;System.out.println(result);A.0B.1 C.2D.5 2)以下程序的运行结果为:1.public class Conditional 2.public static void main(String args )3.int x=4;4.System.out.println(value is +(x 4)?99.99:9);5.6.A.输出:value is 99.99 B.输出:value is 9 C.输出:value is 9.0 D.在第 4 行出现编译错误3)以下代码段的输出结果为1.int x=0,
9、y=4,z=5;2.if(x 2)3.if(y 5)11.System.out.println(message three);12.13.else 14.System.out.println(message four);15.A.message one B.message two C.message three D.message four 4)以下程序的输出结果为:public class test public static void main(String args)int x=1,y=1,z=1;if(x-=1&y+=1|z+=1)System.out.println(x=+x+,y=
10、+y+,z=+z);Ax=0,y=2,z=1 B x=1,y=2,z=1 Cx=0,y=1,z=1 Dx=0,y=2,z=2 5)编译和运行以下代码结果为:1.public class EqualsTest 2.public static void main(String args)3.byte A=(byte)4096;4.if(A=4096)System.out.println(Equal);5.else System.out.println(Not Equal);6.7.A在第 3 行出现转换丢失精度的编译错误.B输出Not Equal.C输出Equal.6)关于以下程序哪条叙述正确?1
11、.int j=2;2.switch(j)3.case 2:4.System.out.println(value is two);5.case 2+1:6.System.out.println(value is three);7.break;8.default:9.System.out.println(value is +j);10.break;11.A.第 5 行的表达式不合法;B.变量 j 是可接受的,switch 中表达式可以是byte,short,int,或 long 的任何类型;C.输出为 value is two D.输出是 value is two 后跟 value is thre
12、e E.输出是 value is two 后跟value is 2 7)以下程序的编译运行结果为:1:public class Q10 2:3:public static void main(String args)4:5:int i=10;6:int j=10;7:boolean b=false;8:9:if(b=i=j)10:System.out.println(True);11:else 12:System.out.println(False);13:14:A.第 9 行出现编译错误;B.第 9 行出现运行错误;C.输出True D.输出False 8)以下程序的编译和运行结果为?cla
13、ss test static boolean check;public static void main(String args)int i;if(check=true)i=1;else i=2;if(i=2)i=i+2;else i=i+4;System.out.println(i);A.3 B.4 C.5 D.6 E.语句 if(i=2)编译出错9)以下代码:if(a 4)System.out.println(test1);else if(a 9)System.out.println(test2);else System.out.println(test3);a 为何值将有输出结果test
14、2?A.小于0 B.小于4 C.4 和 9 之间D.大于 9 E.无任何可能10)有如下代码段:switch(x)case 1:System.out.println(One);break;case 2:case 3:System.out.println(Two);break;default:System.out.println(end);变量 x 的取值下列哪些情形时,能使程序输出Two。A.1 B.2 C.3 D.default 11)以下程序的输出结果为public class test public static void main(String agrs)char c1=B,c2=C;
15、if(c1+1c2)+c1;System.out.println(c1);A.B B.b C.C D.c 12)假设 a是 int 类型变量,并初始化为1,则下列哪个为合法的条件语句?A.if(a)B.if(a3)C.if(a=2)D.if(true)四、循环程序设计1)执行以下程序后,输出结果为public class ex2 public static void main(String args)int f=1;int k;for(k=2;k5;k+)f*=k;System.out.println(k);A.0 B.1 C.5 D.4 E.24 2)设有如下类class Loop publ
16、ic static void main(String agrs)int x=0;int y=0;outer:for(x=0;x100;x+)middle:for(y=0;y100;y+)System.out.println(x=+x+;y=+y);if(y=10)在 处插入什么代码可以结束外循环?Acontinue middle;Bbreak outer;Cbreak middle;Dcontinue outer;Enone of these 3)以下代码的运行结果为:public class Calc public static void main(String args)int total
17、=0;for(int i=0,j=10;total 30;+i,-j)System.out.println(i=+i+:j=+j);total+=(i+j);System.out.println(Total +total);A.产生运行错误B.产生编译错误C.输出Total 0 D.产生如下输出:i=0:j=10 i=1:j=9 i=2:j=8 Total 30 4)以下程序的运行结果为:public class test public static void main(String args)int i=0,j=2;do i=+i;j-;while(j0);System.out.printl
18、n(i);A.0 B.1 C.2.3 5)以下程序的运行结果为?class xyz public static void main(String args)int i,j,k;for(i=0;i 3;i+)for(j=1;j 4;j+)for(k=2;k5;k+)if(i=j)&(j=k)System.out.println(i);A.0 B.1 C.2 D.3 E.4 6)以下程序的运行结果为?class test public static void main(String args)int i,j=0;for(i=10;i-j)continue;while(i5);执行完后,i、j 的值
19、分别为:Ai=6 j=5 Bi=5 j=5 Ci=6 j=4 D i=5 j=6 8)以下程序的输出结果为:public class example public static void main(String args)int s=0;for(int i=0;i3*i;j-)s+=i*j;System.out.println(s);A.127 B.136 C.147 D.153 9)以下程序的输出结果为:public class example public static void main(String args)int i=0;for(i=0;i 4)&(i1-10);f1+=1.0;w
20、hile(!b1);System.out.println(b1+,+i1+,+f1);A.false,9,4.3 B.true,11,1.3 C.false,8,1.3 D.true,8,7.3 五、方法设计1)以下代码的输出结果?public class Test static int x=5;public static void main(String argv)change(x);x+;System.out.println(x);static void change(int m)m+=2;A.7 B.6 C.5 D.8 2)以下代码的输出结果?public class Test int
21、x=5;public static void main(String argv)Test t=new Test();t.x+;change(t);System.out.println(t.x);static void change(Test m)m.x+=2;A.7 B.6 C.5 D.8 3)以下代码的输出结果?public class Test public static void main(String argv)String x=hello;change(x);System.out.println(x);static void change(String m)m=m+2;A.hello
22、 B.hello2 C.编译报错D.运行报错,不能将串与整数相加4)设有如下类:class MyPoint void myMethod()int x,y;x=5;y=3;System.out.print(+x+,+y+);switchCoords(x,y);System.out.print(+x+,+y+);void switchCoords(int x,int y)int temp;temp=x;x=y;y=temp;System.out.print(+x+,+y+);如果执行myMethod()方法,则输出结果为?A.(5,3)(5,3)(5,3)B.(5,3)(3,5)(3,5)C.(5
23、,3)(3,5)(5,3)5)以下程序的输出结果为:public class test public static void main(String args)int s=0;for(int k=0;k=10;k+)s+=method(2,k)-1;System.out.println(s);public static int method(int n,int m)if(m=0)return 1;else return n*method(n,m-1);A.2048 B.1024 C.2036 D.2000 6)以下程序的输出结果为:public class test public static
24、 void main(String args)int m=0;for(int k=0;k2;k+)method(m+);System.out.println(m);public static void method(int m)System.out.print(m);A.000 B.012 C.123 D.111 六、数组的使用1)输入如下命令运行Java 应用程序。java MyTest 1 2 3 则命令行参数数组args 中得到的值哪个正确?A.args0=MyTest 1 2 3 B.args0=1 2 3 C.args0=1 D.args1=1 2 3 2)在注释/Start For
25、 loop 处要插入哪段代码可实现根据变量i 的值定位数组ia 的元素?public class Lin public void amethod()int ia=new int4;/Start For loop iai=i;System.out.println(iai);A.for(int i=0;i ia.length()-1;i+)B.for(int i=0;i ia.length();i+)C.for(int i=1;i 4;i+)D.for(int i=0;i ia.length;i+)3)以下代码的调试结果?public class Q public static void main
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 基础 练习题

限制150内