Java练习题1有答案Word文档格式.docx

上传人:b****6 文档编号:22024797 上传时间:2023-02-02 格式:DOCX 页数:43 大小:32.68KB
下载 相关 举报
Java练习题1有答案Word文档格式.docx_第1页
第1页 / 共43页
Java练习题1有答案Word文档格式.docx_第2页
第2页 / 共43页
Java练习题1有答案Word文档格式.docx_第3页
第3页 / 共43页
Java练习题1有答案Word文档格式.docx_第4页
第4页 / 共43页
Java练习题1有答案Word文档格式.docx_第5页
第5页 / 共43页
点击查看更多>>
下载资源
资源描述

Java练习题1有答案Word文档格式.docx

《Java练习题1有答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《Java练习题1有答案Word文档格式.docx(43页珍藏版)》请在冰豆网上搜索。

Java练习题1有答案Word文档格式.docx

4、Everymethodmustendwithasemicolon;

5、Everyclassmustendwithasemicolon;

答案2

第8题WhichofthefollowingstatementsiscorrecttodisplayWelcometoJavaontheconsole?

1、System.out.println(WelcometoJava);

2、System.out.println("

WelcometoJava"

);

3、System.println(WelcometoJava);

4、System.out.print(WelcometoJava);

5、System.out.print("

答案25

第9题WhichJDKcommandiscorrecttorunaJavaapplicationinByteCode.class?

1、javaByteCode

2、javaByteCode.class

3、javacByteCode.java

4、javacByteCode5、JAVACByteCode答案1第10题SupposeyoudefineaJavaclassasfollows:

publicclassTest{

}

Inordertocompilethisprogram,thesourcecodeshouldbestoredinafilenamed

1、Test.class

2、Test.doc

3、Test.txt

4、Test.java

5、Anynamewithextension.java答案4第11题TheextensionnameofaJavabytecodefileis

1、.java

2、.obj

3、.class

4、.exe答案3第12题WhichofthefollowinglinesisnotaJavacomment?

1、/**comments*/

2、//comments

3、--comments

4、/*comments*/

5、**comments**答案35第13题Whichofthefollowingarethereservedwords?

1、public

2、static

3、void4、class答案1234第14题TouseJOptionPaneinyourprogram,youmayimportitusing:

1、importjavax.swing.JOptionPane;

2、importjavax.swing.*;

3、importjavax.*;

4、importjavax.*.JOptionPane;

答案12

第15题WhichofthefollowingarecorrectnamesforvariablesaccordingtoJavanamingconventions?

1、radius

2、Radius

3、RADIUS

4、findArea5、FindArea答案14第16题Whichofthefollowingarecorrectwaystodeclarevariables?

1、intlength;

intwidth;

2、intlength,width;

3、intlength;

width;

4、intlength,intwidth;

答案12第17题____________istheJavaassignmentoperator.

1、==

2、:

=

3、=

4、=:

答案3第18题Whichofthefollowingassignmentstatementsisincorrect.

1、i=j=k=1;

2、i=1;

j=1;

k=1;

3、i=1=j=1=k=1;

4、i==j==k==1;

答案34第19题Whichofthefollowingisaconstant,accordingtoJavanamingconventions?

1、MAX_VALUE

2、Test

3、read

4、ReadInt5、COUNT答案15第20题Todeclareanintvariablenumberwithinitialvalue2,youwrite

1、intnumber=2L;

2、intnumber=2l;

3、intnumber=2;

4、intnumber=2.0;

答案3第21题Whichofthefollowingexpressionswillyield0.5?

1、1/2

2、1.0/2

3、(double)(1/2)

4、(double)1/25、1/2.0答案245第22题Whichofthefollowingexpressionresultsinavalue1?

1、2%1

2、15%4

3、25%54、37%6答案4第23题-25%5is_____

1、1

2、2

3、3

4、45、0答案5第24题-24%-5is_____

1、3

2、-3

3、4

4、-45、0答案4第25题Toaddnumbertosum,youwrite(Note:

Javaiscase-sensitive)

1、number+=sum;

2、number=sum+number;

3、sum=Number+sum;

4、sum+=number;

5、sum=sum+number;

答案45

第26题Supposexis1.Whatisxafterx-=1?

1、0

2、1

3、2

4、-15、-2答案1第27题Whatisxafterthefollowingstatements?

intx=1;

inty=2;

x*=y+1;

1、xis1;

2、xis2;

3、xis3;

4、xis4;

答案3第28题Whatisydisplayed?

publicclassTest{publicstaticvoidmain(String[]args){intx=1;

inty=x+x++;

System.out.println("

yis"

+y);

1、yis1.

2、yis2.

3、yis3.

4、yis4.答案2第29题Whatisydisplayedinthefollowingcode?

inty=x+++x;

3、yis3.4、yis4.答案3第30题Whatistheprintoutofthefollowingcode:

doublex=5.5;

inty=(int)x;

System.out.println("

xis"

+x+"

andyis"

1、xis5andyis6

2、xis6.0andyis6.0

3、xis6andyis6

4、xis5.5andyis55、xis5.5andyis5.0答案4第31题Supposexisacharvariablewithavalueb.WhatistheprintoutofthestatementSystem.out.println(++x)?

1、a

2、b

3、c4、d答案3第32题Supposeiisaninttypevariable.WhichofthefollowingstatementsdisplaythecharacterwhoseUnicodeisstoredinvariablei?

1、System.out.println(i);

2、System.out.println((char)i);

3、System.out.println((int)i);

4、System.out.println(i+"

"

答案2第33题Thefollowingcodefragmentreadsintwonumbers:

Scannerinput=newScanner(System.in);

inti=input.nextInt();

doubled=input.nextDouble();

Whatarethecorrectwaystoenterthesetwonumbers?

1、Enteraninteger,aspace,adoublevalue,andthentheEnterkey.

2、Enteraninteger,twospaces,adoublevalue,andthentheEnterkey.

3、Enteraninteger,anEnterkey,adoublevalue,andthentheEnterkey.4、Enteranumericvaluewithadecimalpoint,aspace,aninteger,andthentheEnterkey.答案123第34题Ifyouenter123,whenyourunthisprogram,whatwillbetheoutput?

importjava.util.Scanner;

publicclassTest1{

publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);

System.out.print("

Enterthreenumbers:

doublenumber1=input.nextDouble();

doublenumber2=input.nextDouble();

doublenumber3=input.nextDouble();

//Computeaveragedoubleaverage=(number1+number2+number3)/3;

//Displayresult

System.out.println(average);

1、1.0

2、2.0

3、3.0

4、4.0答案2第35题Theexpression(int)(76.0252175*100)/100evaluatesto_________.

1、76.02

2、76

3、76.02521754、76.03答案2第36题AccordingtoJavanamingconvention,whichofthefollowingnamescanbevariables?

1、FindArea

2、findArea

3、totalLength

4、TOTAL_LENGTH

5、class答案23第37题The__________methoddisplaysaninputdialogforreadingastring.

1、Stringstring=JOptionPane.showMessageDialog(null,"

Enterastring"

"

InputDemo"

JOptionPane.QUESTION_MESSAGE);

2、Stringstring=JOptionPane.showInputDialog(null,"

3、Stringstring=JOptionPane.showInputDialog("

"

4、Stringstring=JOptionPane.showInputDialog(null,"

5、Stringstring=JOptionPane.showInputDialog("

答案245第38题Analyzethefollowingcode.

importjavax.swing.*;

publicclassShowErrors{publicstaticvoidmain(String[]args){inti;

intj;

Strings=JOptionPane.showInputDialog(null,

Enteraninteger"

Input"

JOptionPane.QUESTION_MESSAGE);

j=Integer.parseInt(s);

i=(i+4);

1、Theprogramcannotcompilebecausejisnotinitialized.

2、Theprogramcannotcompilebecauseidoesnothaveaninitialvaluewhenitisusedini=i+4;

3、Theprogramcompilesbuthasaruntimeerrorbecauseidoesnothaveaninitialvaluewhenitisusedini=i+4;

4、Theprogramcompilesandrunsfine.答案2第39题Supposex=10andy=10.Whatisxafterevaluatingtheexpression(y>

10)&

&

(x-->

10)?

1、9

2、103、11答案2第40题Supposex=10andy=10whatisxafterevaluatingtheexpression

(y>

=10)||(x++>

10).

2、103、11答案2第41题Supposex=1,y=-1,andz=1.Whatistheprintoutofthefollowingstatement?

(Pleaseindentthestatementcorrectlyfirst.)if(x>

0)if(y>

0)

x>

0andy>

0"

elseif(z>

x<

0andz>

1、x>

0;

2、x<

3、x<

0andz<

4、noprintout.

答案2第42题Analyzethefollowingcode.

booleaneven=false;

if(even){

Itiseven!

1、ThecodedisplaysItiseven!

2、Thecodedisplaysnothing.

3、Thecodeiswrong.Youshouldreplaceif(even)withif(even==true)

4、Thecodeiswrong.Youshouldreplaceif(even)withif(even=true)答案2

第43题Thefollowingcodedisplays___________.

doubletemperature=50;

if(temperature>

=100)System.out.println("

toohot"

elseif(temperature<

=40)System.out.println("

toocold"

else

justright"

1、toohot

2、toocold

3、justright

4、toohottoocoldjustright答案3第44题Analyzethefollowingcode:

Code1:

booleaneven;

if(number%2==0)even=true;

elseeven=false;

Code2:

booleaneven=(number%2==0);

1、Code1hascompileerrors.

2、Code2hascompileerrors.

3、BothCode1andCode2havecompileerrors.

4、BothCode1andCode2arecorrect,butCode2isbetter.答案4第45题The__________methodimmediatelyterminatestheprogram.

1、System.terminate(0);

2、System.halt(0);

3、System.exit(0);

4、System.stop(0);

答案3第46题Whatistheprintou

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

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

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

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