Você está na página 1de 4

Name: test ID:

Email:

CompsciTest_Chap_2_2016

True/False10point
Indicatewhetherthestatementistrueorfalse.

T 1.Ifa,bandcareintvariableswitha=5,b=7,c=12,thenthestatementint
z=(a*bc)/awillresultinzequalto4.

T 2.
YoucannotcastaStringtobeacharandyoucannotcastaStringwhichstoresanumbertobeanintordouble.

F 3.
Themodoperator,%,canonlybeperformedonintvaluesanditsresultisadouble.

F 4.
Sincedoubletointisanarrowingconversion,thereisnowaytoconvertadoubletoanint.

T 5.IfStringa="ABCD"andStringb="abcd"thena.equals(b)returnsfalsebuta.equalsIgnoreCase(b)
returnstrue.

T 6.
IfStringname="GeorgeW.Bush"thentheinstructionname.length()willreturn14.

F 7.
IfxistheString"HiThere",thenx.toUpperCase().toLowerCase()willreturntheoriginalversionofx.

T 8.TheRandomclasshasamethodnextDouble()whichreturnsarandomdoublevaluebetween0and1
exclusive

F 9.
Thewordprintlnisareservedword.

F 10.
Theoperators*and+havethesameprecedence.

MultipleChoice3pointseachtotal60
Identifythechoicethatbestcompletesthestatementoranswersthequestion.

D 11. Ifyouwanttooutputthetext"hithere",includingthequotemarks,whichofthefollowingcoulddothat?
a. System.out.println("hithere")
b. System.out.println(""hithere"")
c. System.out.println("\"hithere")
d. System.out.println("\"hithere\"")
e. none,itisnotpossibletooutputaquotemarkbecauseitisusedtomarkthebeginningandendingofthe
Stringtobeoutput.

E 12. Whatvaluewillzhaveifweexecutethefollowingassignmentstatement?
intz=50/10.00
a. 5
b. 5.0
c. 50
d. 10
e. noneoftheabove,aruntimeerrorarisesbecausezisanintand50/10.00isnot

D 13. Whatwillbetheresultofthefollowingassignmentstatement?Assumeb=5andc=10.
inta=b*(c+2)/2
a. 30
b. 30
c. 20
d. 20
e. 6

C 14. ConsiderhavingthreeStringvariablesa,bandc.Thestatementc=a+bcanalsobeachievedbydoing
a. c=a.length()+b.length()
b. c=(int)a+(int)b
c. c=a.concat(b)
d. c=b.concat(a)
e. c=a.plus(b)

A 15. IntheStringmajor="ComputerScience",whatisreturnedbymajor.charAt(10)?
a. 'c'
b. 'o'
c. 'm'
d. "C"
e. "Computer"

C 16.Sinceyoucannottakethesquarerootofanegativenumber,youmightusewhichofthefollowing
instructionstofindthesquarerootofthevariablex?
a. Math.sqrt(x*x)
b. Math.sqrt((int)x)
c. Math.sqrt(Math.abs(x))
d. Math.abs(Math.sqrt(x))
e. Math.(Math.sqrt(xx))

D 17.WhichofthefollowingwouldreturnthelastcharacteroftheStringx?
a. x.charAt(0)
b. x.charAt(last)
c. x.charAt(length(x))
d. x.charAt(x.length()1)
e. x.charAt(x1)

E 18. IfyouwanttostoreintotheStringnamethevalue"GeorgeBush",youwoulddowhichstatement?
a. Stringname="GeorgeBush"
b. Stringname=newString("GeorgeBush")
c. Stringname="George"+""+"Bush"
d. Stringname=newString("George"+""+"Bush")
e. Anyoftheabovewouldwork

A 19. WhatisoutputwiththestatementSystem.out.println(x+y)
ifxandyareintvalueswherex=10andy=5?
a. 15
b. 105
c. 105
d. x+y
e. AnerrorsinceneitherxnoryisaString

B 20. WhatisoutputwiththestatementSystem.out.println(""+x+y)
ifxandyareintvalueswherex=10andy=5?
a. 15
b. 105
c. 105
d. x+y
e. AnerrorsinceneitherxnoryisaString

A 21.
Assumethatx,yandzareallintsequalto50,20and6respectively.
Whatistheresultofx/y/z?
a. 0
b. 12
c. 16
d. Asyntaxerrorasthisissyntacticallyinvalid
e. Aruntimeerrorbecausethisisadivisionby0

D 22.
Ifyouwanttooutputthetext"hithere",includingthequotemarks,whichofthefollowingcoulddothat?
a. System.out.println("hithere")
b. System.out.println(""hithere"")
c. System.out.println("\"hithere")
d. System.out.println("\"hithere\"")
e. none,itisnotpossibletooutputaquotemarkbecauseitisusedtomarkthebeginningandendingofthe
Stringtobeoutput

E 23.TheexperssionNumber+(6+4*5)willpreducewhichofthefollwoing
a. Number620
b. Number620
c. Number105
d. Number645
e. Number120

E 24.Whatistheoutputofthetheinstruction
num1=(int)(Math.random()*10+1)
a. 010
b. 11
c. 1
d. 0to9
e. 1to10

A 25.num1=generator.nextInt(20)10
a. 10to9
b. 1to10
c. 20to30
d. 0to9
e. 0to11

D 26.num1=(int)(Math.random()*10+1)%2
a. 0
b. 1
c. 2
d. 0or1
e. Error

D 27.WhichstatmentwouldweusetocreatanobjectfromcalssclasscalledDoThis
a. DoThissomething
b. DOThissomething=DOThis()
c. DoThissomething=newDoThis
d. DoThissomething=newDoThis()
e. newDoThis=DoThissomething()


B 28.
whichstatmentwilloutputthefollowingcharactersexactlyasshown:/'\"/'\
a. System.out.println("//\\\"/\'\\")
b. System.out.println("/\'\\\"/\'\\")
c. System.out.println("\'\\\"/\'\\\")
d. System.out.println("/\'\/\'\\")
e. System.out.println("/\'\\\'\\")

C 29.
Assumethata="1",b="2",y=3andz=4.whatistheoutputofthestatements?
System.out.println(a+b+y+z)
a. 10
b. 127
c. 1234
d. 37
e. 334

E 30.whatwouldbetheoutputofthestatment
System.out.println(3*3/2+4%3)
a. 0
b. 1
c. 2
d. 4
e. 5

Essay

31.FRQ30point

Writeacompleteprogramwhichwillprompttheuserandinput3
int values(X,Y,Z), compute the average, and output the result as a
double, and compute and output the values x10 as int values. Assum
thescannerisimported.
publicclassaverage{
publicstaticvoidmain(String[]args){
Scannerscan=newScanner(System.in);
System.out.println("Whatisthefirst
value?");
intX=scan.nextInt();

Você também pode gostar