Exam11301Ch123.docx

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

Exam11301Ch123.docx

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

Exam11301Ch123.docx

Exam11301Ch123

Name:

_______________________

CoversChapters1-3

50mins

CSCI1301IntroductiontoProgramming

ArmstrongAtlanticStateUniversity

Instructor:

Y.DanielLiang

PartI.(10pts)Showtheprintoutofthefollowingcode:

(writetheprintoutnexttoeachprintlnstatementiftheprintlnstatementisexecutedintheprogram).

publicclassTest{

publicstaticvoidmain(String[]args){

System.out.println((int)(Math.random()));

System.out.println(Math.pow(2,3));

System.out.println(34%7);

System.out.println(3+4*2>2*9);

intnumber=4;

if(number%3==0)

System.out.println(3*number);

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:

EntertheexchangeratefromdollarstoRMB:

6.81

Enter0toconvertdollarstoRMBand1viceversa:

0

Enterthedollaramount:

100

$100.0is681.0Yuan

EntertheexchangeratefromdollarstoRMB:

6.81

Enter0toconvertdollarstoRMBand1viceversa:

1

EntertheRMBamount:

10000

10000.0Yuanis$1468.43

 

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

Enteraninteger:

6

Georgia

Enteraninteger:

15

HiFiveGeorgia

Enteraninteger:

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<0)

System.out.print("xislessthan0");

else

System.out.print("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':

case'A':

System.out.print(ch);break;

case'b':

case'B':

System.out.print(ch);break;

case'c':

case'C':

System.out.print(ch);break;

case'd':

case'D':

System.out.print(ch);

}

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.

intx=0;

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:

y=0;

case7:

y=1;

default:

y+=1;

}

a.1

b.4

c.3

d.2

e.0

#

11.Whichofthefollowingcodedisplaystheareaofacircleiftheradiusispositive.

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

b.if(radius!

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

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

d.if(radius>0)System.out.println(radius*radius*3.14159);

 

Solution:

PartI:

0

8.0

6

false

16

9

43

943isodd

0

PartII:

1.

importjava.util.Scanner;

publicclassExercise3_31{

publicstaticvoidmain(String[]args){

Scannerinput=newScanner(System.in);

System.out.print("EntertheexchangeratefromdollarstoRMB:

");

doublerate=input.nextDouble();

System.out.print("Enter0toconvertdollarstoRMBand1viceversa:

");

intconversionType=input.nextInt();

if(conversionType==0){

System.out.print("Enterthedollaramount:

");

doubledollars=input.nextDouble();

doubleRMB=dollars*rate;

System.out.println("$"+dollars+"is"+RMB+"Yuan");

}

else{

System.out.print("EntertheRMBamount:

");

doubleRMB=input.nextDouble();

doubledollars=RMB/rate;

System.out.println(RMB+"Yuan"+"is"+"$"+dollars);

}

}

}

2.

importjava.util.Scanner;

publicclassTest{

publicstaticvoidmain(String[]args){

Scannerinput=newScanner(System.in);

System.out.println("Enteraninteger:

");

intnumber=input.nextInt();

if(number%5==0)

System.out.println("HiFive");

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

System.out.println("Georgia");

}

}

 

PartIII:

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

a.76

b.76.0252175

c.76.03

d.76.02

Key:

a

#

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

Key:

d

#

3.Assumexis0.Whatistheoutputofthefollowingstatement?

if(x>0)

System.out.print("xisgreaterthan0");

elseif(x<0)

System.out.print("xislessthan0");

else

System.out.print("xequals0");

a.xislessthan0

b.xisgreaterthan0

c.xequals0

d.None

Key:

c

#

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.

Key:

d

#

5.Whatistheprintoutofthefollowingswitchstatement?

charch='a';

switch(ch){

case'a':

case'A':

System.out.print(ch);break;

case'b':

case'B':

System.out.print(ch);break;

case'c':

case'C':

System.out.print(ch);break;

case'd':

case'D':

System.out.print(ch);

}

a.ab

b.a

c.aa

d.abc

e.abcd

Key:

b

#

6.Whatisxafterevaluating

x=(2>3)?

2:

3;

a.5

b.2

c.3

d.4

Key:

c

#

7.Analyzethefollowingcode.

intx=0;

if(x>0);

{

System.out.println("x");

}

a.Thevalueofvariablexisalwaysprinted.

b.Thesymbolxisalwaysprintedtwice.

c.Thesymbolxisalwaysprinted.

d.Nothingisprintedbecausex>0isfalse.

Key:

c

#

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;

Key:

a

#

9.Whichofthefollowingisaconstant,accordingtoJavanamingconventions?

a.read

b.MAX_VALUE

c.ReadInt

d.Test

Key:

b

#

10.Whatisyafterthefollowingswitchstatementisexecuted?

x=3;

switch(x+3){

case6:

y=0;

case7:

y=1;

default:

y+=1;

}

a.1

b.4

c.3

d.2

e.0

Key:

d

#

11.Whichofthefollowingcodedisplaystheareaofacircleiftheradiusispositive.

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

b.if(radius!

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

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

d.if(radius>0)System.out.println(radius*radius*3.14159);

Key:

d

 

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

当前位置:首页 > PPT模板 > 卡通动漫

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

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