程序阅读题Word文档格式.docx

上传人:b****1 文档编号:15320304 上传时间:2022-10-29 格式:DOCX 页数:13 大小:18.27KB
下载 相关 举报
程序阅读题Word文档格式.docx_第1页
第1页 / 共13页
程序阅读题Word文档格式.docx_第2页
第2页 / 共13页
程序阅读题Word文档格式.docx_第3页
第3页 / 共13页
程序阅读题Word文档格式.docx_第4页
第4页 / 共13页
程序阅读题Word文档格式.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

程序阅读题Word文档格式.docx

《程序阅读题Word文档格式.docx》由会员分享,可在线阅读,更多相关《程序阅读题Word文档格式.docx(13页珍藏版)》请在冰豆网上搜索。

程序阅读题Word文档格式.docx

__static___inta=666;

A(Strings1){s=s1;

staticintgeta(){returna;

下面是一个类的定义,完成程序填空。

(Youwritethis.x=x;

publicclassYouwrite

intx;

Youwrite____(){x=0;

Youwrite(intx)

{_this.x=x____;

(myclassstatic)

class_______Myclass_____//定义名为myclass的类

_________static_intvar=666;

staticintgetvar()

{returnvar;

1.以下程序段的输出结果为Messagefour

Intx=0,y=4,z=5;

If(x>

2){

If(y<

5){

System.out.println(“Messageone”);

Else

System.out.println(“MessageTwo”);

Elseif(z>

System.out.println(“Messagethree”);

}else{System.out.println(“Messagefour”);

2.写出以下程序的输出结果Valueistwo.

Valueisthree.

Intj=2;

Switch(j){

Case2:

System.out.println(“Valueistwo.”);

Case2+1:

System.out.println(“Valueisthree.”);

Break;

Default:

System.out.println(“Valueis”+j);

3.写出以下程序的输出结果

*

**

***

****

*****

For(inti=1;

i<

=5;

i++)

For(intj=1;

j<

=i;

j++)

System.out.print(“*”);

System.out.println(“”);

4.下列程序运行后,输出的结果是__556__

publicclassTest{

publicstaticvoidmain(String[]args){

intc=5;

System.out.println(c);

System.out.println(c++);

5.下列程序运行后,输出的结果是__i>

8__

publicclassIfelse{

inti=9;

if(i<

3)

System.out.println(“i<

3”);

else

8)

System.out.println(“3<

8”);

System.out.println(“i>

6.下列程序运行后,输出的结果是_defaultZeroOne_

publicclassBase{

publicstaticvoidmain(String[]args){

inti=4;

switch(i){

default:

System.out.print(“default”);

case0:

System.out.print(“Zero”);

case1:

System.out.print(“One”);

break;

case2:

System.out.print(“Two”);

下面方法的功能是在命令行打印list对象,请将程序补充完整。

privatestaticvoidprintArrayList(Listlist)

{Iteratoriterator=__List___;

//得到list的迭代器

while(iterator.hasNext())//迭代器中是否有下一个元素

System.out.println(___list_____);

//显示迭代器中的元素

根据程序中的注释,将下面的应用程序补充完整。

publicclassA{

publicstaticvoidmain(String[]args){

Aa=newB();

a.test();

voidtest(){

System.out.print("

A"

);

classB____extends____A{

______;

//调用父类的同名方法

System.out.println("

B"

下面程序的功能是通过调用方法max()求给定的三个数的最大值,

请将其补充完整。

(max(i1,i2,i3)static)

publicclassClass1

publicstaticvoidmain(Stringargs[])

inti1=1234,i2=456,i3=-987;

intMaxValue;

MaxValue=_max(i1,i2,i3)___________;

System.out.println("

三个数的最大值:

"

+MaxValue);

public___static___intmax(intx,inty,intz)

{inttemp1,max_value;

temp1=x>

y?

x:

y;

max_value=temp1>

z?

temp1:

z;

returnmax_value;

下面是定义一个接口ITF的程序,完成程序填空。

(interfaceabstract)

public_interface______ITF

publicstaticfinaldoublePI=Math.PI;

publicabstract___doublearea(doublea,doubleb);

下面是定义一个接口A的程序,完成程序填空。

(final”;

”)

publicinterfaceA

publicstatic___final____doublePI=3.14159;

publicabstractdoublearea(doublea,doubleb)___;

_

1.publicclassSum{

publicstaticvoidmain(String[]args){

intj=10;

jis:

"

+j);

calculate(j);

Atlast,jis:

staticvoidcalculate(intj){

for(inti=0;

10;

j++;

jincalculate()is:

输出结果为:

 

(1)

jincalculate()is:

(2)

Atlastjis:

(3)

答案:

(1)10;

(2)20;

(3)10。

2.按要求填空

abstractclassSuperAbstract{

voida(){…}

abstractvoidb();

abstractintc(inti);

interfaceAsSuper

voidx();

abstractclassSubAbstractextendsSuperAbstractimplementsAsSuper

publicvoidb(){…}

abstractStringf();

publicclassInheritAbstractextendsSubAbstract{

publicvoidx(){…}

publicintc(inti){…}

publicStringf(){…}

publicstaticvoidmain(Stringargs[]){

InheritAbstractinstance=newInheritAbstract();

instance.x();

instance.a();

instance.b();

instance.c(100);

System.out.println(instance.f());

}

在以上这段程序中:

抽象类有:

SuperAbstract和 

(1)  (写出类名)

非抽象类有:

       

(2)  (写出类名)

接口有:

         (3)  (写出接口名)

AsSuper中的x()方法是(4)方法,所以在InheritAbstract中必须对它进行(5)       

(1)SuperAbstract;

(2)InheritAbstract;

(3)AsSuper;

(4)抽象;

(5)覆盖和实现。

3.按注释完成程序

publicclassLeaf{

privateinti=0;

//此属性值用于检验

Leafincrement(){//定义方法increment(),返回值是Leaf类的对象

i++;

return

(1);

//将当前对象的地址作为返回值返回

voidprint(){

i="

+i);

Leafx=

(2);

//创建Leaf类的对象x

x.increment().increment().increment().print();

}//多次调用方法increment(),返回的

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 职业规划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1