第一范文网 - 专业文章范例文档资料分享平台

Java基础练习题附答案

来源:用户分享 时间:2025/5/22 15:22:18 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

word格式

以下哪些语句编译不出错?

A.c=c+i; B. s+=i; C. i+=s; D. c+=s; 15) 整型变量a,b的值定义如下: int a=3; int b=4;

则表达式 ++a==b的值为:

A.4 B.false C.3 D.true 16) 执行下列代码后输出结果为: public class test {

public static void main(String args[]) { int a=2; int b=3; int c=7; int d=a>c?a:c; d=d>>2>b? d:b; System.out.println(b); } }

A.2 B.3 C.5 D.7

三、分支程序设计

1)下列语句片段的结果为 int result; int a=17,b=6;

result=(a%b>4)? a%b:a/b ; System.out.println(result); A. 0 B. 1 C. 2 D. 5 2)以下程序的运行结果为: 1. public class Conditional {

2. public static void main(String args [] ) { 3. int x = 4;

4. System.out.println( \ 5. } 6. }

A. 输出:value is 99.99 B. 输出: value is 9

.. ..

word格式

C. 输出: value is 9.0 D. 在第4行出现编译错误 3)以下代码段的输出结果为 1. int x = 0, y = 4, z = 5; 2. if (x > 2) { 3. if (y < 5) {

4. System. out .println ( \5. } 6. else {

7. System.out.println( \8. } 9. }

10. else if (z > 5) {

11. System.out.println(\12. } 13. else {

14. System.out.println( \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(\ } }

A. x=0,y=2,z=1 B. x=1,y=2,z=1 C. x=0,y=1,z=1 D. x=0,y=2,z=2

5) 编译和运行以下代码结果为:

.. ..

word格式

1. public class EqualsTest{

2. public static void main(String args[]){ 3. byte A=(byte)4096;

4. if(A==4096) System.out.println(\5. else System.out.println(\6. } 7. }

A.在第3行出现转换丢失精度的编译错误. B.输出 \C.输出 \

6) 关于以下程序哪条叙述正确? 1. int j = 2; 2. switch ( j ) { 3. case 2:

4. System.out.println (\5. case 2 + 1:

6. System.out.println (\7. break; 8. default:

9. System.out.println(\10. break; 11. }

A. 第5行的表达式不合法;

B. 变量j是可接受的,switch中表达式可以是byte, short, int,或long的任何类型;

C. 输出为value is two

D. 输出是value is two 后跟value is three 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;

.. ..

word格式

7: boolean b = false; 8:

9: if( b = i == j)

10: System.out.println(\11: else

12: System.out.println(\13: } 14: }

A. 第9行出现编译错误; B. 第9行出现运行错误; C. 输出 True D. 输出 False

8)以下程序的编译和运行结果为? class 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(\else if (a >9)

System.out.println(\else

System.out.println(\a为何值将有输出结果test2 ?

.. ..

搜索更多关于: Java基础练习题附答案 的文档
Java基础练习题附答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6w3fx7spq025ui718xfz9x6b742s6901dui_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top