Sei sulla pagina 1di 3

I.

Fill in the Blanks (15x2) If-Else While Array If Do-while or Return Break !en"th Switch Continue Statement

Decision control structures Multidimensional arrays Repetition control structures

1. In #a$a% the &&&&&&& structure pro$ides the mechanism to perform one action when a Boolean e'pression
e$aluates as true% and performs a different action when a Boolean e'pression e$aluates as false(

2. A &&&&&&& loop e'ecutes a )ody of statements continually as lon" as the Boolean e'pression that controls
entry into the loop continues to )e true(

3. *he &&&&&&& structure is the fundamental control structure that allows #a$a to make decisions or to e'ecute
statements conditionally(

4. A &&&&&&& is one or more lines of code endin" with a semicolon and "enerally contains e'pressions( 5. A &&&&&&& statement tells the #a$a interpreter to stop e'ecutin" the current method( 6. *he &&&&&&& loop e'ecutes a loop )ody at least one time and checks the loop control $aria)le at the )ottom
of the loop after one repetition has occurred(

7. &&&&&&& are #a$a statements that allow a pro"rammer to select and e'ecute specific )locks of code while
skippin" other sections(

8. A &&&&&&& statement when e'ecuted skips any remainin" statements in the )ody of the structure and
proceeds with the test for the ne't iteration of the loop(

9. *he &&&&&&& structure is useful when you need to test a sin"le $aria)le a"ainst a series of e'act inte"er or
character $alues(

10. A &&&&&&& loop is a special loop that can )e used when a definite num)er of loop iteration is re+uired( 11. &&&&&&& contain two or more dimensions( 12. &&&&&&& are #a$a statements that allow a pro"rammer to e'ecute specific )locks of code a num)er of times( 13. A,n- &&&&&&&&&& is a data structure whose elements are accessed )y means of inde' positions( 14. *he &&&&&&&&&& field contains the num)er of elements in an array( 15. *he &&&&&&&&&& statement is used to .)reak out/ of a loop(
II. Multiple Choice (10x2)

1. If you declare an inte"er array as int01 num 2 3454% 656% 757% 858% 959:;% the array element num061 contains
a(

the num)er &&&&&( 454 b. 656 c. 757 d. 858

2. *he statement int01 $alue 2 new int0781; reser$es memory for &&&&& inte"ers( a( 5 b. 77 c. 78 d. 79 3. If you declare an array as int01 num 2 new int0<1;% the final element of the array is &&&&&( a( num051 b. num041 c. num091 d. num0<1 4. Assume an array is declared as int01 num 2 new int081;( Which of the followin" statements correctly assi"ns
a( )(

the $alue 455 to each of the four array elements= for,'25; '>7; ??'- num0'1 2 455; c. for,'24; '>7; ??'- num0'1 2 455; for,'25; '>8; ??'- num0'1 2 455; d. for,'24; '>9; ??'- num0'1 2 455;

5. Assumin" the $aria)le + has )een assi"ned the $alue 7% which of the followin" statements prints @@@= a( if,+ A 5- System(out(println,.@@@/-; c. Both of the statements print @@@ )( if,+ A 5-; System(out(println,.@@@/-; d. Beither of the statements prints @@@ 6. When you code an if statement within another if statement% as in if,a A )- if,c A d- ' 2 5;% the if statements areC a( notched b. nestled c. nested d. sheltered 7. What is the output of the followin"=
) 2 4; while ,) > 83 System(out(print,) ? . /-; ) 2 ) ? 4; :
a(

b. 4 6 7

c. 4 4 4 4 4D

d. 4 6 7 8

8. If total 2 455 and amt 2 655% then after the statement total ?2 amt% &&&&&&&&&&( a( total is e+ual b. total is e+ual c. amt is e+ual to d. amt is e+ual to
to 655
Pre-Final Exa ination

to 755

455

755
* Property of STI Pa!e 1 o" #

9. What does the followin" pro"ram se"ment print=


d 2 5; do 3 System(out(print,d ? . /-; d??; : while ,d > 6a(

)( 5 4

c(

546

d( Bone of these

10. *he statement for,a24; aA7; ??a- System(out(print,a ? . .-; prints &&&&&&&&&&( a( 4 4 4 c. 4 6 7 8 )( 4 6 7 d. Bone of these
III. Pro!ra $racin! (#x10)

1. Consider the followin" code snippet( What output do you think the code will produce if ansBum is 7=
if ,aBum)er A2 5- 3 if ,aBum)er 22 5- 3 System(out(println,Efirst strin"E-; : else 3 System(out(println,Esecond strin"E-; : : System(out(println,Ethird strin"E-;

2. What is the output of the pro"ram=


pu)lic class ControlStruct 3 pu)lic static $oid main,Strin"01 ar"s- 3 for , int num)er 2 4; num)er >2 45; num)er?? - 3 System(out(print,num)er-; if , ,num)er F 6- 22 5 - 3 System(out(print,E )lueE-; : if , ,num)er F 8- 22 5 - 3 System(out(print,E redE-; : if , ,num)er F <- 22 5 - 3 System(out(print,E yellowE-; : System(out(println,-; : : :

3. What is the output of the pro"ram=


pu)lic class Sin"leDimArray 3 static $oid main,Strin"01 ar"s- 3 pu)lic

Pre-Final Exa ination

* Property of STI Pa!e 2 o" #

dou)le empBasicGay01 2 38555% 9555% 46555% <555%H955:; dou)le empIousin"Allow01 2 new dou)le091; int i; for,i25; i>9; i??3 empIousin"Allow0i1 2 5(6 - empBasicGay0i1; : System(out(println,.Employee Basic and Iouse Rental Allowance/-; for,i25; i>9; i??- 3 System(out(println,empBasicGay0i1 ? . / ? empIousin"Allow0i1-; : : :

I%. Pro!ra 4( 6(

in! (20 points)

Write a #a$a pro"ram that will display all e$en num)ers from 4 to 455( Write a #a$a pro"ram that will display all e$en num)ers from 4 to 455(

Pre-Final Exa ination

* Property of STI Pa!e # o" #

Potrebbero piacerti anche