Questions and Verified Answers
ConsiderAtheAfollowingAmethod.
publicAstaticAintAmystery(int[]Aarr)
{
AintAxA=A0
forA(intAkA=A0;AkA<Aarr.length;AkA=AkA+A2)
AxA=AxA+Aarr[k]
returnAx;
}
AssumeAthatAtheAarrayAnumsAhasAbeenAdeclaredAandAinitializedAasAfollows.
Aint[]AnumsA=A{3,A6,A1,A0,A1,A4,A2};
(A)A5
(B)A6
(C)A7
(D)A10
(E)A17A-ACORRECTAANSWERSA-(C)A7
ConsiderAtheAfollowingApartialAclassAdeclaration.
publicAclassASomeClass
{
privateAintAmyA;
privateAintAmyB;
privateAintAmyC;
//AConstructor(s)AnotAshown
publicAintAgetA
{AreturnAmyA;A}
publicAvoidAsetB(intAvalue)
{AmyBA=Avalue;A}
TheAfollowingAdeclarationAappearsAinAanotherAclass.
SomeClassAobjA=AnewASomeClass();
WhichAofAtheAfollowingAcodeAsegmentsAwillAcompileAwithoutAerror?
(A)AintAxA=Aobj.getA();
(B)AintAx;
Aobj.getA(x);
(C)AintAxA=Aobj.myA
(D)AintAxA=ASomeClass.getA();
(E)AintAxA=AgetA(obj);A-ACORRECTAANSWERSA-(A)AintAxA=Aobj.getA
WhichAofAtheAfollowingAchangesAtoASomeClassAwillAallowAotherAclassesAtoAaccessAbutAnotA
modifyAtheAvalueAofAmyCA?
, (A)AMakeAmyCApublic.
(B)ApublicAintAgetC()
A{AreturnAmyC;A}
(C)AprivateAintAgetC()
A{AreturnAmyC;A}
(D)ApublicAvoidAgetC(intAx)
(E)AprivateAvoidAgetC(intAx)
A{AxA=AmyC;A}A-ACORRECTAANSWERSA-(B)ApublicAintAgetC()
A{AreturnAmyC;A}
ConsiderAtheAfollowingAcodeAsegment.
AintAxA=A7;
AintAyA=A3;
A
AifA((xA<A10)A&&A(yA<A0))
ASystem.out.printIn("ValueAis:A"A+AxA*Ay);
Aelse
ASystem.out.printIn("Value Ais:A"A+AxA/Ay);
WhatAisAprintedAasAaAresultAofAexecutingAtheAcodeAsegment
(A)AValueAis:A21
(B)AValueAis:A2.3333333
(C)AValueAis:A2
(D)AValueAis:A0
(E)AValueAis:A1A-ACORRECTAANSWERSA-(B)A2.3333333
ConsiderAtheAfollowingAmethod.
publicAArrayList<Integer>Amystery(intAn)
{
AArrayList<Integer>AseqA=AnewAArrayList<Integer>();
AforA(intAkA=A1;AkA<=An;Ak++)
Aseq.add(newAInteger(kA*AkA+A3));
A
AreturnAseq
}
WhichAofAtheAfolowingAisAprintedAasAaAresultAofAexecutingAtheAfollowingAstatement?
ASystem.out.printIn.(mystery(6));
(A)A[3,A4,A7,A12,A19,A28]
(B)A[3,A4,A7,A12,A19,A28,A39]
(C)A[4,A7,A12,A19,A28,A39]
(D)A[39,A28,A19,A12,A7,A4]
(E)A[39,A28,A19,A12,A7,A4,A3]A-ACORRECTAANSWERSA-(C)A[4,A7,A12,A19,A28,A39]
/**A@returnAtrueAifAd1AandAd2AareAwithinAtheAspecifiedAtolerance
*AfalseAotherwise
*/
publicAbooleanAalmostEqual(doubleAd1,AdoubleAd2,AdoubleAtolerance)