Exam11301Ch123Word文件下载.docx

上传人:b****5 文档编号:20573341 上传时间:2023-01-24 格式:DOCX 页数:12 大小:16.64KB
下载 相关 举报
Exam11301Ch123Word文件下载.docx_第1页
第1页 / 共12页
Exam11301Ch123Word文件下载.docx_第2页
第2页 / 共12页
Exam11301Ch123Word文件下载.docx_第3页
第3页 / 共12页
Exam11301Ch123Word文件下载.docx_第4页
第4页 / 共12页
Exam11301Ch123Word文件下载.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

Exam11301Ch123Word文件下载.docx

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

Exam11301Ch123Word文件下载.docx

System.out.println(4*number);

intx=943;

System.out.println(x/100);

System.out.println(x%100);

System.out.println(x+"

is"

+((x%2==0)?

"

even"

:

odd"

));

inty=-1;

y++;

System.out.println(y);

}

}

PartII:

1.(10pts)WriteaprogramthatpromptstheusertoentertheexchangeratefromcurrencyUSdollarstoChineseRMB.Prompttheusertoenter0toconvertfromUSdollarstoChineseRMBand1viceversa.PrompttheusertoentertheamountinUSdollarsorChineseRMBtoconvertittoChineseRMBorUSdollars,respectively.Herearethesampleruns:

<

Output>

EntertheexchangeratefromdollarstoRMB:

6.81

Enter0toconvertdollarstoRMBand1viceversa:

0

Enterthedollaramount:

100

$100.0is681.0Yuan

EndOutput>

1

EntertheRMBamount:

10000

10000.0Yuanis$1468.43

 

2.(10pts)Writeaprogramthatpromptstheusertoenteraninteger.Ifthenumberisamultipleof5,printHiFive.Ifthenumberisdivisibleby2or3,printGeorgia.Herearethesampleruns:

Enteraninteger:

6

Georgia

15

HiFiveGeorgia

25

HiFive

PartIII:

MultipleChoiceQuestions:

(1ptseach)

(Pleasecircleyouranswersonpaperfirst.Afteryoufinishthetest,enteryourchoicesonlinetoLiveLab.LoginandclickTakeInstructorAssignedQuiz.ChooseQuiz1.Youhave5minutestoenterandsubmittheanswers.)

1.Theexpression(int)(76.0252175*100)/100evaluatesto_________.

a.76

b.76.0252175

c.76.03

d.76.02

#

2.Whatisyafterthefollowingswitchstatement?

intx=0;

inty=0;

switch(x+1){

case0:

y=0;

case1:

y=1;

default:

y=-1

a.2

b.1

c.0

d.-1

3.Assumexis0.Whatistheoutputofthefollowingstatement?

if(x>

0)

System.out.print("

xisgreaterthan0"

);

elseif(x<

xislessthan0"

else

xequals0"

a.xislessthan0

b.xisgreaterthan0

c.xequals0

d.None

4.Analyzethefollowingcode:

Code1:

booleaneven;

if(number%2==0)

even=true;

else

even=false;

Code2:

booleaneven=(number%2==0);

a.Code2hassyntaxerrors.

b.Code1hassyntaxerrors.

c.BothCode1andCode2havesyntaxerrors.

d.BothCode1andCode2arecorrect,butCode2isbetter.

5.Whatistheprintoutofthefollowingswitchstatement?

charch='

a'

;

switch(ch){

case'

:

A'

System.out.print(ch);

break;

b'

B'

c'

C'

d'

D'

a.ab

b.a

c.aa

d.abc

e.abcd

6.Whatisxafterevaluating

x=(2>

3)?

2:

3;

a.5

b.2

c.3

d.4

7.Analyzethefollowingcode.

if(x>

0);

{

System.out.println("

x"

a.Thevalueofvariablexisalwaysprinted.

b.Thesymbolxisalwaysprintedtwice.

c.Thesymbolxisalwaysprinted.

d.Nothingisprintedbecausex>

0isfalse.

8.TodeclareaconstantMAX_LENGTHinsideamethodwithvalue99.98,youwrite

a.finaldoubleMAX_LENGTH=99.98;

b.doubleMAX_LENGTH=99.98;

c.finalMAX_LENGTH=99.98;

d.finalfloatMAX_LENGTH=99.98;

9.Whichofthefollowingisaconstant,accordingtoJavanamingconventions?

a.read

b.MAX_VALUE

c.ReadInt

d.Test

10.Whatisyafterthefollowingswitchstatementisexecuted?

x=3;

switch(x+3){

case6:

case7:

y+=1;

a.1

b.4

d.2

e.0

11.Whichofthefollowingcodedisplaystheareaofacircleiftheradiusispositive.

a.if(radius<

=0)System.out.println(radius*radius*3.14159);

b.if(radius!

c.if(radius>

d.if(radius>

0)System.out.println(radius*radius*3.14159);

Solution:

PartI:

8.0

6

false

16

9

43

943isodd

1.

importjava.util.Scanner;

publicclassExercise3_31{

Scannerinput=newScanner(System.in);

System.out.print("

doublerate=input.nextDouble();

intconversionType=input.nextInt();

if(conversionType==0){

doubledollars=input.nextDouble();

doubleRMB=dollars*rate;

$"

+dollars+"

+RMB+"

Yuan"

}

else{

doubleRMB=input.nextDouble();

doubledollars=RMB/rate;

System.out.println(RMB+"

+"

+dollars);

2.

Scannerinput=newScanner(System.in);

intnumber=input.nextInt();

if(number%5==0)

HiFive"

if(number%2==0||number%3==0)

Georgia"

Key:

a

d

c

b

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

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

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

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