QUIZ 5 – RESULT.

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

Java Control Statements
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Introduction to C Programming
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
8-May-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Repetition Statements Recitation – 02/20/2009 CS 180 Department of Computer Science, Purdue University.
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
16-Jun-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
CS150 Introduction to Computer Science 1
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
Looping Yong Choi School of Business CSU, Bakersfield.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
COM S 207 While-Loop Statement Instructor: Ying Cai Department of Computer Science Iowa State University
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
Using Shortcut Arithmetic Operators Accumulator: A variable that is used to total. Its value is repeatedly increased by some amount. Java provides shortcuts.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Repetition Statements while and do while loops
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
1-Dec-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
CSC 212 Object-Oriented Programming and Java Part 2.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
Printing with for Loops To print a character multiple times, use a for loop. for (int j = 1; j
For Loop Tips And Tricks
Fundamental Programming Fundamental Programming More on Repetition.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
LOOPS IN ‘C’ PROGRAMMING. V ERY O FTEN, Y OU W ILL W ANT TO D O S OMETHING M ORE T HAN O NCE HA.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
UCT Department of Computer Science Computer Science 1015F Iteration
Chapter 9 Repetition.
CS 1430: Programming in C++ No time to cover HiC.
Chapter 6 More Conditionals and Loops
CiS 260: App Dev I Chapter 4: Control Structures II.
TK1114 Computer Programming
Chapter 5 Repetition.
The University of Texas Rio Grande Valley
The University of Texas – Pan American
Outline Altering flow of control Boolean expressions
The University of Texas – Pan American
Chapter 9 Control Structures.
Introduction to Programming
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
Repetition Control Structure
CS 200 Loops Jim Williams, PhD.
Building Java Programs
Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell.
What output is produced by the following fragment?
Case & Repetitive Statements
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
PROGRAM FLOWCHART Iteration Statements.
Building Java Programs
Controlling Program Flow
Presentation transcript:

QUIZ 5 – RESULT

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

QUIZ 5 – SOLUTION

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

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 = 0 TRUE 0 0+1 = 1 j = 1 TRUE 1 1+1 = 2 j = 2 TRUE 2 2+1 = 3 j = 3 TRUE 3 3+1 = 4 j = 4 TRUE 4 4+1 = 5 j = 5 FALSE EXIT Answer: 0 1 2 3 4

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 = 10 TRUE 10 10-1 = 9 j = 9 TRUE 9 9-1 = 8 j = 8 TRUE 8 8-1 = 7 j = 7 TRUE 7 7-1 = 6 j = 6 TRUE 6 6-1 = 5 j = 5 FALSE EXIT 10 9 8 7 6

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

Question 5: What must the change be so that the following fragment prints out the even integers 0 2 4 6 8 10? for (int j = 0; j <= 10; __________)   System.out.print( j + " " ); Initialization Condition Print Decrement Answer: j = j + 2

Question 6: What must the initialization be so that the following fragment prints out the integers -3 -2 -1 ? for ( _______; j < 0; j++) System.out.print( j + " " ); Initialization Condition Print Decrement Answer: j = -3

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 1+1=2 2 x = 2 TRUE 2+1=3 3 x = 3 TRUE 3+1=4 4 x = 4 TRUE 4+1=5 5 x = 5 FALSE EXIT EXIT Answer: 2 3 4 5

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: 3 7 12 18 25 33 42

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 = 1 1 1 + 1 = 2 TRUE X = 2 2 2 + 1 = 3 TRUE X = 3 3 3 + 1 = 4 TRUE X = 4 4 4 + 1 = 5 FALSE EXIT EXIT EXIT EXIT Answer: 1 2 3 4

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 12 + 6 = 18 6 + 1 = 7 k = 7 tot = 18 18 + 7 = 25 7 + 1 = 8 k = 8 tot = 25 25 + 8 = 33 8 + 1 = 9 k = 9 tot = 33 33 + 9 = 42 9 + 1 = 10 k = 10 tot = 42 42 + 10 = 52 10 + 1 = 11 FALSE 52 int k = 3; int tot = 0; do { tot = tot + k; k++; } while (k < 11); System.out.println(tot); Answer: 52

MST REVISION Date: Friday 22th March Time: 12:00 – 2:00pm Location: Lab 2

SECTION A: MULTIPLE CHOICE (8 marks) Review Quiz 1 to Quiz 5 Review Activity 1 to 7 Lecture 1 to 13

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)

SECTION C: PROGRAM WORKTHROUGH(20 marks) LOOP

Review Questions

_____ 3 + 6 + 9 / 3 evaluates to 6. _______________________________________________________ ___________   _____ A test before loop will be executed at least once.

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