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

Java基础练习题附答案

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

word格式

9) 以下程序的输出结果为: public class example {

public static void main(String args[]) { int i=0;

for (i=0;i<4;i++) { if (i==3) break;

System.out.print(i); }

System.out.println(i); } }

A.0123 B.0122 C.123 D.234 10) 以下程序的运行结果为 class Prob10 { static boolean b1;

public static void main(String [] args) { int i1 = 11; double f1=1.3; do {

b1 = (f1 > 4) && (i1-- < 10); f1 += 1.0; } while (!b1);

System.out.println(b1 + \ } }

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++;

.. ..

word格式

System.out.println(x); }

static void change(int m){ m+=2; } }

A. 7 B. 6 C. 5 D. 8 2) 以下代码的输出结果? public class Test{ int 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=\ change(x);

System.out.println(x); }

static void change(String m){ m=m+2; } }

A. hello B. hello2

C. 编译报错 D. 运行报错,不能将串与整数相加 4)设有如下类:

.. ..

word格式

class MyPoint { void myMethod() { int x, y; x = 5; y = 3;

System.out.print( \ switchCoords( x, y );

System.out.print( \ }

void switchCoords( int x, int y ) { int temp; temp = x; x = y; y = temp;

System.out.print( \ } }

如果执行myMethod()方法,则输出结果为? A. (5, 3) (5, 3) (5, 3) B. (5, 3) (3, 5) (3, 5) C. (5, 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); } }

.. ..

word格式

A. 2048 B. 1024 C. 2036 D.2000 6) 以下程序的输出结果为: public class test {

public static void main(String args[]) { int m=0;

for ( int k=0;k<2;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 \

则命令行参数数组args中得到的值哪个正确? A. args[0] = \B. args[0] = \C. args[0] = \D. args[1]= \

2) 在注释//Start For loop 处要插入哪段代码可实现根据变量i的值定位数组ia[]的元素? public class Lin{ public void amethod(){ int ia[] = new int[4]; //Start For loop {

ia[i]=i;

System.out.println(ia[i]); } } }

.. ..

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