Beruflich Dokumente
Kultur Dokumente
Commonerrors
Hereisalistofcommonerrorsthatstudentshavecommittedinpreviousexams.Youwill
receivenocreditforananswerthatcommitsanyoftheseerrors!
1.Youarenotallowedtocolloboratewithanotherpersonbefore,duringoraftertheexam.The
workyousubmitmustbeyourown.Ifwedetectananswerthatwasclearlysharedamongst
twoormoreapplicants,wewillstopgradingthetestandallapplicantsinvolvedwillfailthe
test!!.Don'tcolloborate!!
2.Donothardcodethelengthofanarray.Justbecausetheexamplesrequireanarrayoflength
3,say,doesnotmeanthatyourprogramshouldbeabletoonlyhandlearraysoflength3.
Yourprogramshouldbeabletohandleanarrayofanysize!Soifweseesomethinglike
int[]a=newint[3]
wewillstopgradingandgiveyouzeropointsfortheanswer.
3.DonotuseanyI/Oinyourfunctions!Youshouldnotreadinanythingfromthekeyboardor
writeoutanythingtotheconsole.Afunctionshouldgetitsinputfromitsparametersand
returnitsanswerusingareturnstatement.Specifically,yourfunctionmustbeabletobeused
asisinaGUIbasedwindowsapplicationorinabrowserbasedwebapplication.Soifwesee
anyofthefollowingstatementsinyourfunction,wewillstopgradingandyouwillreceive
nocreditforyouranswer.
1.cout
2.cin
3.printf
4.scanf
5.Console.WriteLine()
6.Console.ReadLine()
7.System.out.println()
8.System.in.read()
9.AnyotherI/Ostatement
4.Thesignatureofthefunctionyouwritemustmatchthesignaturegiveninthequestion.Soif
thequestionspecifiesthesignature
intfoo(int[]a)
thenyouranswershouldlooksomethinglikethis:
intfoo(int[]a)
{
//dosomethingwitha
//returnanint
}
Hereisanexamplethatfailstomeetthisrequirementbecauseitdoesnotreturnanint
voidfoo(int[]a)
{
//dosomethingwitha
//printresult
}
Hereisanotherexamplethatfailsbecauseitdoesnottakeanarrayasaparameter
http://www.mumde.net/pretest/commonerrors.htm
1/2
10/19/2016
Commonerrors
intfoo()
{
//Dosomethingwitha,whichinthiscaseiseitheraglobalvariableoraninstancevariable.
//returnanint
}
Inparticular,youwillreceivenocreditforyouranswerifyouonlyhaveamainprogram,
e.g.,
main(...)
{
int[]a=newint[]{1,2,3};
//dosomethingwitha
//printoutresult.
}
5.Yourfunctionshouldnotalterreferenceinputparameter(s)inanywayunlessthequestion
specificallysaystodoso.Forexample,ifthequestionasksyoutoreturnthemaximumvalue
ofanarray,thefollowingsolutionisincorrecteventhoughitreturnsthecorrectmaximum.
Theproblemisthatitalsorearrangesalltheelementsofthearraythisisanundesirableside
effectthatwillbeseenbythecallerofthefunction.Rememberthatarraysarepassedby
referencenotbyvalue!
staticintfindMax(int[]a)
{
//Sortthearrayusingabubblesort
intj=a.length1;
booleansorted=false;
while(!sorted)
{
sorted=true;
for(inti=0;ia[i+1])
{
intswap=a[i];
a[i]=a[i+1];
a[i+1]=swap;
sorted=false;
}
}
}
//Thearrayisnowsortedintoascendingorder
//sothelastelementisthemaximumelement
returna[a.length1];
}
Bytheway,noneofourquestionswillrequireyousortanyinputparameter.Ifyouchooseto
dosopleasesortacopyoryouwillreceivenocreditforthequestion.
http://www.mumde.net/pretest/commonerrors.htm
2/2