java资料Word格式.docx

上传人:b****7 文档编号:22226519 上传时间:2023-02-03 格式:DOCX 页数:22 大小:29.72KB
下载 相关 举报
java资料Word格式.docx_第1页
第1页 / 共22页
java资料Word格式.docx_第2页
第2页 / 共22页
java资料Word格式.docx_第3页
第3页 / 共22页
java资料Word格式.docx_第4页
第4页 / 共22页
java资料Word格式.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

java资料Word格式.docx

《java资料Word格式.docx》由会员分享,可在线阅读,更多相关《java资料Word格式.docx(22页珍藏版)》请在冰豆网上搜索。

java资料Word格式.docx

C)L=f+i;

D)s=s+i+f+d;

7.以下语句输出的结果是(A

Stringstr="

intx=4,y=5;

str=str+(x+y);

System.out.println(str);

A)1239B)12345C)会产生编译错误D)123+4+5

8.以下语句中没有编译错误或警告提示信息的是(B)?

A)byteb=256;

B)doubled=89L;

C)charc="

a"

D)shorts=8.6f;

9.下面的程序输出结果是:

1+2=3,请将程序补充完整。

publicclassApp2{

publicstaticvoidmain(Stringargs[]){

intx=1,y=2;

System.out.println(______________);

}

}

答案:

x+"

+"

+y+"

="

+(x+y)

10.阅读下面的程序,回答问题。

程序如下:

publicclassApp1{

charch='

\n'

System.out.print("

Thefirstsnowcame,"

+ch+"

Howbeautifulitwas!

"

);

}

(1)这是哪一类java程序?

(2)写出保存该文件的文件名及后缀名?

(3)在JDK下编译该文件的命令是什么?

编译后形成什么文件?

(4)在JDK下如何运行该程序?

程序运行后输出的结果如何?

10.答案:

(1)Java应用程序(JavaApplication);

(2)App1.java;

(3)在命令行用javacApp1.java编译该程序。

编译后形成App1.class的字节码文件;

(4)在命令行键入javaApp1即可运行该程序。

编程序运行后输出的结果为:

Thefirstsnowcame,

Howbeautifulitwas!

11.阅读下面的程序,回答问题。

importjava.applet.Applet;

importjava.awt.Graphics;

publicclassApplet1extendsApplet{

publicvoidpaint(Graphicsg){

g.drawString("

Welcome"

25,30);

to"

85,30);

Java"

25,50);

Programming!

55,50);

(4)该程序能直接运行吗?

写出嵌入该程序的字节码文件的html文件,该html文件可以任意命名吗?

(5)程序运行后输出几行?

写出输出结果。

11.答案:

(1)Java小程序(JavaApplet)。

(2)Applet1.java

(3)在命令行用javacApplet1.java编译该程序。

编译后形成Applet1.class的字节码文件。

(4)不能,为了能使程序运行,还需编写html文件,用<

applet>

<

/applet>

标记符将编译形成的字节码文件嵌入到html文件中,然后通过浏览器运行JavaApplet。

或在命令行通过命令appletviewer运行html文件。

嵌入该程序的字节码文件的html文件如下,该html文件可以任意命名(如命名为mypage.htm)

mypage.htm文件如下:

HTML>

HEAD>

TITLE>

我的网页<

/TITLE>

/HEAD>

BODY>

APPLETcode=Applet1.classwidth=300height=200>

/APPLET>

/BODY>

/HTML>

(5)程序运行后输出2行;

输出结果如下:

第2章使用Java解决简单的问题

1.以下选项中变量均已正确定义,错误的赋值语句是(D)。

A)i--;

B)i+=7;

C)k+=x+2;

D)y+x=z;

2.若以下变量均已正确定义并赋值,下面符合Java语言语法的表达式是(B)。

A)a=a≤7B)a=7+b+c

C)int12.3%4D)a=a+7=c+b

3.定义整型变量:

intn=456;

,表达式的值为5的是(AB)。

A)n/10%10B)(n-n/100*100)/10

C)n%10D)n/10

4.对下面的语句序列正确的说法是(B)。

intc='

A'

/3;

c+='

1'

%5;

System.out.println(c);

A)产生编译错误;

B)输出结果25;

C)输出结果21;

D)输出结果2;

5.设a,f,x,y,z均为int型的变量,并已赋值,下列表达式的结果属于非逻辑值的是(D)。

A)x>

y&

&

f<

aB)-z<

x-y

C)y!

=++xD)y+x*x++

6.执行下列程序段后,b,x,y的值正确的是(C)。

intx=6,y=8;

booleanb;

b=x<

y|++x==--y;

A)true,6,8B)false,7,7

C)true,7,7D)false,6,8

7.下面的程序段输出的变量b的值是(B)。

inta=0xFFFFFFFE;

intb=~a;

System.out.println("

b="

+b);

A)0xFFFFFFFEB)1C)14D)-2

8.若a和b均是整型变量并已正确赋值,正确的switch语句是(A)。

A)switch(a+b);

B)switch(a+b*3.0)

{……}{……}

C)switchaD)switch(a%b)

9.以下由do-while语句构成的循环执行的次数是(D)。

A)无限次B)有语法错,不能执行

C)一次也不执行D)执行1次

intk=0;

do{++k;

}while(k<

1);

10.执行完下面的程序段后,k的值是(B)。

intk=0;

label:

for(inti=1;

i<

10;

i++)

{

for(intj=1;

j<

5;

j++)

{

k+=i+j;

if(j==3)

breaklabel;

}

A)3B)9C)12D)6

11.下列方法x的定义中,正确的是(A)。

A)intx(){charch='

a'

return(int)ch;

}B)voidx{...}

C)intx(inti){return(double)(i+10);

}D)x(inta){returna;

12.下列方法定义中,方法头不正确的是(D)。

A)publicintx(){...}B)publicstaticintx(doubley){...}

C)voidx(doubled)D)publicstaticx(doublea){...}

13.为了区分重载多态中同名的不同方法,要求(A)。

A)采用不同的形式参数列表B)返回值类型不同

C)参数名不同D)选项A、B、C都对

14.在某个类中定义一个方法:

voidGetSort(intx),以下能作为这个方法的重载的是(ABCD)。

A.voidGetSort(floatx){x*=x;

B.intGetSort(doubley){return(int)(2*y);

C.doubleGetSort(intx,inty){returnx+y;

D.voidGetSort(intx,inty){x=x+y;

y=x-y}

15.若已定义:

inta[]={0,1,2,3,4,5,6,7,8,9};

则对a数组元素正确的引用是(B)。

A)a[-3]B)a[9]C)a[10]D)a(0)

16.下面是在命令行运行Java应用程序A,怎样才能在main(Stringargs[])方法中访问单词"

first"

(BD)?

javaAthefirstsnow,thefirstsnowcame.

A)args[0]B)args[1]C)args[2]D)args[5]

2.判断一个数是否是回文数。

根据/**/中的注释将下面的程序补充完整,使之编译通过并能正确运行。

importjava.awt.*;

importjavax.swing.JOptionPane;

publicclassPalindrome{

//mainmethodbeginsexecutionofJavaapplication

publicstaticvoidmain(Stringargs[])

StringresultString;

//resultString

intnumber;

//userinputnumber

intoriginalNumber;

//storesoriginalvalueinnumberforoutput

intdigit1;

//firstdigit

intdigit2;

//seconddigit

intdigit4;

//fourthdigit

intdigit5;

//fifthdigit

intdigits;

//numberofdigitsininput

number=0;

digits=0;

/*Writecodethatinputsafive-digitnumber.Displayanerrormessage

ifthenumberisnotfivedigits.Loopuntilavalidinputisreceived.*/

/*Writecodethatseparatesthedigitsinthefivedigitnumber.Use

divisiontoisolatetheleft-mostdigitinthenumber,usearemainder

calculationtoremovethatdigitfromthenumber.Thenrepeatthis

process.StoretheoriginalvalueofnumberinvariableoriginalNumber

beforeperformingcalculations.*/

/*Writecodethatdetermineswhetherthefirstandlastdigitsare

identicalandthesecondandfourthdigitsareidentical.Assign

resultStringastringindicatingwhetherornottheoriginalstring

isapalindrome.*/

/*Displaywhetherornotthegivennumberisapalindrome.*/

System.exit(0);

}//endmethodmain

}//endclassPalindrome

第3章类、类的继承和接口

3.下列选项中,用于在定义类头时声明父类名的关键字是(D)。

A)packageB)interfaceC)classD)extends

4.定义类头时可以使用的访问控制符是(CD)。

A)privateB)protected

C)publicD)缺省的,即没有访问控制修饰符

5.有一个类A,对于其构造函数的声明正确的是(B)。

A)voidA(intx){...}B)A(intx){...}

C)AA(intx){...}D)intA(intx){...}

7.设类B是类C的父类,下列声明对象x1的语句中不正确的是(D)。

A)Bx1=newB();

B)Bx1=newC();

C)Cx1=newC();

D)Cx1=newB();

8.编译运行下面的程序,结果是(A)。

publicclassA{

publicstaticvoidmain(String[]args){

Bb=newB();

this.test();

publicvoidtest(){

System.out.print("

A"

classBextendsA{

voidtest(){

super.test();

System.out.println("

B"

A)产生编译错误,因为类B覆盖类A的方法test()时,降低了其访问控制的级别。

B)代码可以编译运行,并输出结果:

AB。

C)代码可以编译运行,但没有输出。

D)代码可以编译运行,并输出结果:

A。

9.下面的程序编译运行的结果是(A)。

publicclassAimplementsB{

intm,n;

At=newA();

m=t.k;

n=B.k;

System.out.println(m+"

"

+n);

interfaceB{intk=5;

A)5,5B)0,5C)0,0D)编译程序产生编译错误

10.为了使包abc中的所有类在当前程序中可见,可以使用的语句是(A)。

A)importabc.*;

B)packageabc.*;

C)importabc;

D)packageabc;

 

2.下面的程序Complex.java定义一个复数类,ComplexTest.java测试该复数类。

============================

//ComplexTest.java

//TesttheComplexnumberclass

importjavax.swing.*;

publicclassComplexTest{

Complexa,b;

a=newComplex(9.9,7.7);

b=newComplex(1.4,3.1);

Stringresult="

a="

+a.toComplexString();

result+="

\nb="

+b.toComplexString();

\na+b="

+a.add(b).toComplexString();

\na-b="

+a.subtract(b).toComplexString();

JOptionPane.showMessageDialog(null,result,"

ComplexTest"

JOptionPane.INFORMATION_MESSAGE);

=========================

//Complex.java

//DefinitionofclassComplex

publicclassComplex{

privatedoublereal;

privatedoubleimaginary;

//Initializebothpartsto0

/*Writeheaderforano-argumentconstructor.*/

{

/*WritecodeherethatcallstheComplexconstructorthattakes2

argumentsandinitializesbothpartsto0*/

//Initializerealparttorandimaginaryparttoi

/*Writeheaderforconstructorthattakestwoarguments梤ealpartrand

imaginaryparti.*/

/*Writelineofcodethatsetsrealparttor.*/

/*Writelineofcodethatsetsimaginaryparttoi.*/

//AddtwoComplexnumbers

publicComplexadd(Complexright)

/*WritecodeherethatreturnsaComplexnumberinwhichtherealpartis

thesumoftherealpartofthisComplexobjectandtherealpartofthe

Complexobjectpassedtothemethod;

andtheimaginarypartisthesum

oftheimaginarypartofthisComplexobjectandtheimaginarypartof

theComplexobjectpassedtothemethod.*/

//SubtracttwoComplexnumbers

publicComplexsubtract(Complexright)

thedifferencebetweentherealpartofthisComplexobjectandthereal

partoftheComplexobjectpassedtothemethod;

andtheimaginarypart

isthedifferencebetweentheimaginarypartofthisComplexobjectand

theimaginarypartoftheComplexobjectpassedtothemethod.*/

//ReturnStringrepresentationofaComplexnumber

publicStringtoComplexString()

return"

("

+real+"

"

+imaginary+"

)"

}//endclassComplex

第4章Java系统类库和常用数据结构

1.定义字符串s:

Strings=”Micrsoft公司”;

执行下面的语句,c的值为(B)。

charc=s.charAt(9);

A)产生数组下标越界异常。

B)司C)nullD)

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

当前位置:首页 > 高等教育 > 文学

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

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