COMPUTER PROGRAMMING EXAM 2
QUESTIONS AND CORRECT
ANSWERS
WhatA2willA2theA2followingA2codeA2print?:A2intA2count;A2forA2(countA2=A210;A2countA2>A26;A2c
ount--)A2System.out.print(countA2+A2"A2");A2-A2Ans--10A29A28A27
WhatA2isA2theA2valueA2ofA2theA2expressionA2(xA2>A23)A2||
A2(yA2<A23)A2ifA2xA2hasA2theA2valueA21A2andA2yA2hasA2theA2valueA25?A2-A2Ans--
TheA2valueA2ofA2thisA2expressionA2isA2False
TheA2bodyA2ofA2anyA2whileA2loopA2willA2beA2executedA2atA2leastA2once.A2-A2Ans--
FalseA2(bodyA2willA2beA2executedA2atA2leastA2once)
EveryA2statementA2withA2ifA2mustA2alsoA2includeA2elseA2-A2Ans--
False,A2everyA2ifA2statementA2willA2notA2alsoA2includeA2"else".
WhatA2isA2outputA2byA2theA2followingA2code?A2
intA2pA2=A24;A2intA2mA2=A230,A2j;A2forA2(jA2=A21;A2jA2<A2p;A2j++);
A2{A2mA2=A2mA2+A2jA2*A2j;A2}A2System.out.println(m);A2-A2Ans--34
AnA2!A2inA2anA2expressionA2means:A2-A2Ans--Not
AA2do-whileA2loopA2willA2loopA2atA2leastA2once.A2-A2Ans--(false)A2doA2while
WhatA2willA2theA2followingA2codeA2print?
A2intA2colorA2=A21;A2switchA2(color)A2{A2caseA21:A2caseA22:A2System.out.print("redA2");A2case
A23:A2System.out.print("blueA2");A2caseA24:A2System.out.print("purple"); A2break;A2default:A2
System.out.print("gray");A2}A2-A2Ans--RedA2BlueA2Purple
WriteA22A2lineA2codeA2snippetA2usingA2aA2for-
loopA2thatA2willA2printA2theA2numbersA218,A26,A22A2-A2Ans--
for(intA2iA2=A218;A2iA2>=2;A2iA2=A2i/3)
System.out.println(i);
AA2multibranchA2if-elseA2statementA2isA2oneA2kindA2ofA2nestedA2if-elseA2statement.A2-
A2Ans--True,A2IsA2aA2nestedA2statement
A(n)A2__________A2goesA2inA2theA2parenthesesA2followingA2theA2wordA2ifA2inA2anA2if-
elseA2statement.A2-A2Ans--ParameterA2List
WhatA2isA2outputA2byA2theA2followingA2code?
A2intA2b;A2forA2(intA2iMusA2=A20;A2iMusA2<A25;A2iMus+
QUESTIONS AND CORRECT
ANSWERS
WhatA2willA2theA2followingA2codeA2print?:A2intA2count;A2forA2(countA2=A210;A2countA2>A26;A2c
ount--)A2System.out.print(countA2+A2"A2");A2-A2Ans--10A29A28A27
WhatA2isA2theA2valueA2ofA2theA2expressionA2(xA2>A23)A2||
A2(yA2<A23)A2ifA2xA2hasA2theA2valueA21A2andA2yA2hasA2theA2valueA25?A2-A2Ans--
TheA2valueA2ofA2thisA2expressionA2isA2False
TheA2bodyA2ofA2anyA2whileA2loopA2willA2beA2executedA2atA2leastA2once.A2-A2Ans--
FalseA2(bodyA2willA2beA2executedA2atA2leastA2once)
EveryA2statementA2withA2ifA2mustA2alsoA2includeA2elseA2-A2Ans--
False,A2everyA2ifA2statementA2willA2notA2alsoA2includeA2"else".
WhatA2isA2outputA2byA2theA2followingA2code?A2
intA2pA2=A24;A2intA2mA2=A230,A2j;A2forA2(jA2=A21;A2jA2<A2p;A2j++);
A2{A2mA2=A2mA2+A2jA2*A2j;A2}A2System.out.println(m);A2-A2Ans--34
AnA2!A2inA2anA2expressionA2means:A2-A2Ans--Not
AA2do-whileA2loopA2willA2loopA2atA2leastA2once.A2-A2Ans--(false)A2doA2while
WhatA2willA2theA2followingA2codeA2print?
A2intA2colorA2=A21;A2switchA2(color)A2{A2caseA21:A2caseA22:A2System.out.print("redA2");A2case
A23:A2System.out.print("blueA2");A2caseA24:A2System.out.print("purple"); A2break;A2default:A2
System.out.print("gray");A2}A2-A2Ans--RedA2BlueA2Purple
WriteA22A2lineA2codeA2snippetA2usingA2aA2for-
loopA2thatA2willA2printA2theA2numbersA218,A26,A22A2-A2Ans--
for(intA2iA2=A218;A2iA2>=2;A2iA2=A2i/3)
System.out.println(i);
AA2multibranchA2if-elseA2statementA2isA2oneA2kindA2ofA2nestedA2if-elseA2statement.A2-
A2Ans--True,A2IsA2aA2nestedA2statement
A(n)A2__________A2goesA2inA2theA2parenthesesA2followingA2theA2wordA2ifA2inA2anA2if-
elseA2statement.A2-A2Ans--ParameterA2List
WhatA2isA2outputA2byA2theA2followingA2code?
A2intA2b;A2forA2(intA2iMusA2=A20;A2iMusA2<A25;A2iMus+