Download presentation
Presentation is loading. Please wait.
1
QUIZ 5 – RESULT
2
QUIZ 5 RESULT Total number of Students = 24 Pass = 14 Fail = 10 Marks
7 2 6 4 5 8 3 1 Total number of Students = 24 Pass = 14 Fail = 10
3
QUIZ 5 – SOLUTION
4
Question 1: How many times will the following loop execute
Question 1: How many times will the following loop execute? for (j=1; j<=3; j--); for (initialization; continuation condition, decrement) j=1 true j=0 true j= -1 true j= -2 true j= -3 true j= -4 true j= -5 Condition never FALSE / LOOP FOREVER (E) A - 1 B - 2 C - 3 D - Never E – Forever
5
Question 2: What is the output of the following program fragment?
for ( int j = 0; j < 5; j++ ) { System.out.print( j + " " ); } System.out.println( ); Initialization Condition Print Increment j = TRUE = 1 j = TRUE = 2 j = TRUE = 3 j = TRUE = 4 j = TRUE = 5 j = FALSE EXIT Answer:
6
Question 3: What is the output of the following program fragment?
for ( int j = 10; j > 5; j-- ) { System.out.print( j + " " ); } Initialization Condition Print Decrement j = TRUE = 9 j = TRUE = 8 j = TRUE = 7 j = TRUE = 6 j = TRUE = 5 j = FALSE EXIT
7
Question 4: What must the test be so that the following fragment prints out the integers, 5 through and including 15? for ( int j = 5; ________; j++ ) { System.out.print( j + " " ); } Initialization Condition Print Decrement Answer: j<=15
8
Question 5: What must the change be so that the following fragment prints out the even integers ? for (int j = 0; j <= 10; __________) System.out.print( j + " " ); Initialization Condition Print Decrement Answer: j = j + 2
9
Question 6: What must the initialization be so that the following fragment prints out the integers ? for ( _______; j < 0; j++) System.out.print( j + " " ); Initialization Condition Print Decrement Answer: j = -3
10
Question 7: What is the output for this program?
int x = 1; while (x < 5){ x++; System.out.println(x); } Initialization Condition Increment Print x = 1 TRUE =2 2 x = 2 TRUE =3 3 x = 3 TRUE =4 4 x = 4 TRUE =5 5 x = 5 FALSE EXIT EXIT Answer:
11
Question 8: What is the output for this program?
int z = 2; int sum = 0; while (z < 9){ z++; sum=sum+z System.out.println(sum); } Answer:
12
Question 9: What is the output for this program?
int x = 1; do { System.out.println(x); x++; } while (x < 5); Initialization Print Increment Condition X = = 2 TRUE X = = 3 TRUE X = = 4 TRUE X = = 5 FALSE EXIT EXIT EXIT EXIT Answer:
13
Question 10: What is the output for this program?
INITIALIZATION INCREMENT CONDITION (k < 11) PRINT (tot) k tot tot = tot + k k++ k = 3 tot = 0 0 + 3 = 3 3 + 1 = 4 True None k = 4 tot = 3 3 + 4 = 7 4 + 1 = 5 k = 5 tot = 7 7 + 5 = 12 5 + 1 = 6 k = 6 tot = 12 = 18 6 + 1 = 7 k = 7 tot = 18 = 25 7 + 1 = 8 k = 8 tot = 25 = 33 8 + 1 = 9 k = 9 tot = 33 = 42 9 + 1 = 10 k = 10 tot = 42 = 52 = 11 FALSE 52 int k = 3; int tot = 0; do { tot = tot + k; k++; } while (k < 11); System.out.println(tot); Answer: 52
14
MST REVISION Date: Friday 22th March Time: 12:00 – 2:00pm
Location: Lab 2
15
SECTION A: MULTIPLE CHOICE (8 marks)
Review Quiz 1 to Quiz 5 Review Activity 1 to 7 Lecture 1 to 13
16
SECTION B: SHORT ANSWER (32 marks)
OOP (advantages) Loops (for loop, while loop, do while loop) SELECTION STRUCTURES (IF and Else statement) Syntax errors correction If and else if vs if statement Write and if statement code Give selection structure code and ask question Syntax errors correction (Ako e if and else statement ke ma’u lelei) If and else if vs if statement (give two code and ask to compare) Write an if statement code Oop (Encapsulation) Loop (differenciate)
17
SECTION C: PROGRAM WORKTHROUGH(20 marks)
LOOP
18
Review Questions
20
_____ / 3 evaluates to 6. _______________________________________________________ ___________ _____ A test before loop will be executed at least once.
23
Explain and differentiate the three types of loop and how they work
Explain and differentiate the three types of loop and how they work. (6marks) __________________________________________________________________ Compare this source code below and explain the different when executed. (5 marks) Code 1 Code 2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.