《JV程序设计》习题Word文件下载.docx

上传人:b****5 文档编号:15975586 上传时间:2022-11-17 格式:DOCX 页数:12 大小:17.93KB
下载 相关 举报
《JV程序设计》习题Word文件下载.docx_第1页
第1页 / 共12页
《JV程序设计》习题Word文件下载.docx_第2页
第2页 / 共12页
《JV程序设计》习题Word文件下载.docx_第3页
第3页 / 共12页
《JV程序设计》习题Word文件下载.docx_第4页
第4页 / 共12页
《JV程序设计》习题Word文件下载.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

《JV程序设计》习题Word文件下载.docx

《《JV程序设计》习题Word文件下载.docx》由会员分享,可在线阅读,更多相关《《JV程序设计》习题Word文件下载.docx(12页珍藏版)》请在冰豆网上搜索。

《JV程序设计》习题Word文件下载.docx

publicStringtoString()

returns1+s2;

运行结果:

Hello!

IloveJAVA

2、importjava.io.*;

publicclassabc

{

publicstaticvoidmain(Stringargs[])

{inti,s=0;

inta[]={10,20,30,40,50,60,70,80,90};

for(i=0;

i<

a.length;

i++)

if(a[i]%3==0)s+=a[i];

System.out.println("

s="

+s);

S=180

//****3、importjava.io.*;

System.out.println("

a="

+a+"

\nb="

+b);

classSubClassextendsSuperClass

{intc;

SubClass(intaa,intbb,intcc)

super(aa,bb);

c=cc;

classSubSubClassextendsSubClass

{inta;

SubSubClass(intaa,intbb,intcc)

{super(aa,bb,cc);

A=aa+bb+cc;

voidshow()

+b+"

\nc="

+c);

a=60b=20c=30

4、以下程序的输出结果为_Peteris17yearsold!

________________。

publicclassPerson{

Stringname;

intage;

publicPerson(Stringname,intage){

this.name=name;

this.age=age;

publicstaticvoidmain(String[]args){

Personc=newPerson("

Peter"

17);

System.out.println(c.name+"

is"

+c.age+"

yearsold!

5、以下程序的输出结果为__课程号:

101课程名:

ASP学分:

3___________________。

publicclassCourse{

privateStringcNumber;

privateStringcName;

privateintcUnit;

publicCourse(Stringnumber,Stringname,intunit){

cNumber=number;

cName=name;

cUnit=unit;

publicvoidprintCourseInfo(){

System.out.println("

课程号:

+cNumber+"

课程名:

+cName+"

学分:

+cUnit);

classCourseTest{

Coursec;

c=newCourse("

101"

"

ASP"

3);

c.printCourseInfo();

6、以下程序的输出结果为__汤姆猫体重:

20.0斤___________________。

publicclassTom{

privatefloatweight;

privatestaticStringname;

publicvoidsetWeight(floatweight){

this.weight=weight;

privatevoidout(){

System.out.println(name+"

体重:

+weight+"

斤"

Tom.name="

汤姆猫"

;

Tomcat=newTom();

cat.setWeight(20);

cat.out();

7、以下程序的输出结果_姓名:

Tom年龄:

15家庭住址:

金水区电话:

_66123456学校:

九中_______________。

publicclassFather{

Stringname,address,tel;

publicFather(Stringname,intage){

voidout(){

System.out.print("

姓名:

+name);

年龄:

+age);

voidoutOther(){

家庭住址:

+address);

电话:

+tel);

classSonextendsFather{

Stringschool;

publicSon(Stringname,intage){

super(name,age);

super.out();

super.outOther();

学校:

+school);

publicstaticvoidmain(Stringargs[]){

Sonson=newSon("

Tom"

15);

son.address="

金水区"

son.school="

九中"

son.tel="

66123456"

son.out();

8、下列程序的运行结果是____12345_________________。

publicclassMyClass{

inta[]={1,2,3,4,5};

for(intj=0;

j<

a.length;

j++)

System.out.print(a[j]+"

MyClassmy=newMyClass();

my.out();

程序填空题

1.publicclassSum{

publicstaticvoidmain(String[]args){

intj=10;

jis:

"

+j);

calculate(j);

Atlast,jis:

staticvoidcalculate(intj){

for(inti=0;

i<

10;

i++)

j++;

jincalculate()is:

输出结果为:

 

(1)10

jincalculate()is:

(2)20

Atlastjis:

(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)  (写出类名)SubAbstract

非抽象类有:

       

(2)  (写出类名)InheritAbstract接口有:

         (3)  (写出接口名)AsSuper

AsSuper中的x()方法是抽象(4)方法,所以在InheritAbstract中必须对它进行覆盖和实现(5)   

3.按注释完成程序

publicclassLeaf{

privateinti=0;

//此属性值用于检验

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

i++;

returnthis

(1);

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

voidprint(){

i="

+i);

Leafx=newLeaf()

(2);

//创建Leaf类

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

当前位置:首页 > 外语学习 > 日语学习

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

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