CSC 1214: Object-Oriented Programming
|
|
- Wilfred McKinney
- 5 years ago
- Views:
Transcription
1 CSC 1214: Object-Oriented Programming J. Kizito Makerere University www: materials: e-learning environment: office: block A, level 3, department of computer science alt. office: institute of open, distance, and elearning, room 2 Control Flow Statements, Arrays, and Iterators Kizito (Makerere University) CSC 1214 February, / 17
2 Overview 1 Control Flow Introduction Conditional Statements Looping Statements Branching Arrays Iterators Kizito (Makerere University) CSC 1214 February, / 17
3 Introduction Control Flow Statements Statements and Blocks An expression followed by a semicolon becomes a x = 0; i++; System.out.print(...); The semicolon is a terminator Braces { and are used to group s into a compound or block There is no semicolon after the right brace that ends a block Kizito (Makerere University) CSC 1214 February, / 17
4 Introduction Control Flow Statements Overview Conditional s: a conditional lets us choose which will be executed next 1 The if 2 The if-else 3 The else-if 4 The switch Iteration/looping s: a looping lets us execute a several times 1 The while loop 2 The do-while loop 3 The for loop Branching 1 The break 2 The continue Kizito (Makerere University) CSC 1214 February, / 17
5 Conditional Statements Control Flow Statements If[-Else] Syntax Examples if (expression) 1 [else 2] 1 if(a < b) a = 0; else b = 0; 2 3 if(a % 2 == 0) System.out.print("even"); if (bytesavailable > 0) { ProcessData(); bytesavailable -= n; else waitformoredata(); Kizito (Makerere University) CSC 1214 February, / 17
6 Conditional Statements Control Flow Statements If[-Else] Syntax Examples if (expression) 1 [else 2] 1 if(a < b) a = 0; else b = 0; 2 3 if(a % 2 == 0) System.out.print("even"); if (bytesavailable > 0) { ProcessData(); bytesavailable -= n; else waitformoredata(); Kizito (Makerere University) CSC 1214 February, / 17
7 Conditional Statements Control Flow Statements Else-If Syntax Example if (expression) else if (expression) else if (expression) //... [else ] if(month == 12 month == 1 month == 2) season = "Winter"; else if(month == 3 month == 4 month == 5) season = "Spring"; else if(month == 6 month == 7 month == 8) season = "Summer"; else if(month == 9 month == 10 month == 11) season = "Autumn"; else season = "Bogus Month"; Kizito (Makerere University) CSC 1214 February, / 17
8 Conditional Statements Control Flow Statements Else-If Syntax Example if (expression) else if (expression) else if (expression) //... [else ] if(month == 12 month == 1 month == 2) season = "Winter"; else if(month == 3 month == 4 month == 5) season = "Spring"; else if(month == 6 month == 7 month == 8) season = "Summer"; else if(month == 9 month == 10 month == 11) season = "Autumn"; else season = "Bogus Month"; Kizito (Makerere University) CSC 1214 February, / 17
9 Conditional Statements Control Flow Statements Switch Syntax Example switch (expression) { case value1: s break; case value2: s break; //... default: s for(int i=0; i<6; i++) switch(i) { case 0: System.out.println("i is zero."); break; case 1: System.out.println("i is one."); break; case 2: System.out.println("i is two."); break; case 3: System.out.println("i is three."); break; default: System.out.println("i is greater than 3."); Kizito (Makerere University) CSC 1214 February, / 17
10 Conditional Statements Control Flow Statements Switch Syntax Example switch (expression) { case value1: s break; case value2: s break; //... default: s for(int i=0; i<6; i++) switch(i) { case 0: System.out.println("i is zero."); break; case 1: System.out.println("i is one."); break; case 2: System.out.println("i is two."); break; case 3: System.out.println("i is three."); break; default: System.out.println("i is greater than 3."); Kizito (Makerere University) CSC 1214 February, / 17
11 Looping Statements Loops While and For Syntax Examples while (expression) for (expr1; expr2; expr3) Conventionally, expr1 initialization, expr2 condition, and expr3 iteration 1 2 int n = 10; while(n > 0) { n--; for(n=10; n>0; n--) Kizito (Makerere University) CSC 1214 February, / 17
12 Looping Statements Loops While and For Syntax Examples while (expression) for (expr1; expr2; expr3) Conventionally, expr1 initialization, expr2 condition, and expr3 iteration 1 2 int n = 10; while(n > 0) { n--; for(n=10; n>0; n--) Kizito (Makerere University) CSC 1214 February, / 17
13 Looping Statements Loops While and For Syntax Examples while (expression) for (expr1; expr2; expr3) Conventionally, expr1 initialization, expr2 condition, and expr3 iteration 1 2 int n = 10; while(n > 0) { n--; for(n=10; n>0; n--) Kizito (Makerere University) CSC 1214 February, / 17
14 Looping Statements Loops While and For Syntax Examples while (expression) for (expr1; expr2; expr3) Conventionally, expr1 initialization, expr2 condition, and expr3 iteration 1 2 int n = 10; while(n > 0) { n--; for(n=10; n>0; n--) Kizito (Makerere University) CSC 1214 February, / 17
15 Looping Statements Control Flow Statements Loops do-while Syntax Example do while (expression); int n = 10; do { n--; while(n > 0); // more efficiently... do { while(--n > 0); Kizito (Makerere University) CSC 1214 February, / 17
16 Looping Statements Control Flow Statements Loops do-while Syntax Example do while (expression); int n = 10; do { n--; while(n > 0); // more efficiently... do { while(--n > 0); Kizito (Makerere University) CSC 1214 February, / 17
17 Looping Statements Control Flow Statements Loops do-while Syntax Example do while (expression); int n = 10; do { n--; while(n > 0); // more efficiently... do { while(--n > 0); Kizito (Makerere University) CSC 1214 February, / 17
18 Branching Control Flow Statements Break, Continue, and Return int i, sum; int a[] = { 31, -28, 31, 30, -31, 30, 31, 31, 0, 31, 30, 31 ; startloop: // label for (i = 0, sum = 0; i < n; i++) { if (a[i] == 0) // 0 terminates loop break; else if (a[i] == -1) break startloop; // a form of Goto else if (a[i] == -2) return; else if (a[i]<0) /* skip negative elements */ continue; sum += a[i]; // do elements greater than 0 System.out.println("sum: " + sum); // do more if didn t return Kizito (Makerere University) CSC 1214 February, / 17
19 Arrays Arrays An array is a group of like-type variables that are referred to by a common name Arrays can be of any type Arrays may have one or more dimensions A specific element in an array is accessed by its index Kizito (Makerere University) CSC 1214 February, / 17
20 Arrays Arrays One-Dimensional Arrays General form type var-name[]; var-name = new type[size]; Examples 1 2 int month days[]; month days = new int[12]; int month days[] = new int[12]; Indexing the array month days[1] = 28; System.out.println(month days[3]); Kizito (Makerere University) CSC 1214 February, / 17
21 Arrays One-Dimensional Arrays Example (1) class Array { public static void main(string args[]) { int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ; System.out.println("April has " + days[3] + " days."); Kizito (Makerere University) CSC 1214 February, / 17
22 Arrays Multidimensional Arrays Examples two dimensional int twod1[][] = new int[4][5]; double m[][] = { {0*0, 1*0, 2*0, 3*0, {0*1, 1*1, 2*1, 3*1, {0*2, 1*2, 2*2, 3*2, {0*3, 1*3, 2*3, 3*3 ; char[][] twod2 = new char[3][4]; Kizito (Makerere University) CSC 1214 February, / 17
23 Arrays Two-Dimensional Arrays Example (2) class TwoDArray { public static void main(string args[]) { int i, j, k = 0, twod[][] = new int[4][5]; for(i = 0; i < 4; i++) for (j = 0; j < 5; j++) twod[i][j] = k++; for(i = 0; i < 4; i++) { for(j = 0; j < 5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); Output: Kizito (Makerere University) CSC 1214 February, / 17
24 Arrays Two-Dimensional Arrays Example (2) class TwoDArray { public static void main(string args[]) { int i, j, k = 0, twod[][] = new int[4][5]; for(i = 0; i < 4; i++) for (j = 0; j < 5; j++) twod[i][j] = k++; for(i = 0; i < 4; i++) { for(j = 0; j < 5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); Output: Kizito (Makerere University) CSC 1214 February, / 17
25 Iterators Iterators Collection classes provide an iterator() method that returns an iterator to the start of the collection Collection classes and interfaces include: - Classes AbstractCollection AbstractList AbstractSequentialList LinkedList ArrayList AbstractSet HashSet TreeSet Interfaces Collection List ListIterator Iterator Set SortedSet Text: java.util Part 1: The Collections Framework. Chapter 15 of The Complete Reference Java TM 2, by Patrick Naughton & Herbert Schildt, Fifth Edition We await discussion on classes, and later on, interfaces... Kizito (Makerere University) CSC 1214 February, / 17
26 Iterators Iterators Example (3) import java.util.*; class IteratorDemo { public static void main(string args[]) { // create an array list ArrayList al = new ArrayList(); al.add("c"); // add elements to the array list al.add("a"); al.add("e"); al.add("b"); al.add("d"); al.add("f"); // use iterator to display contents of al System.out.print("Original contents of al: "); Iterator itr = al.iterator(); while(itr.hasnext()) { Object element = itr.next(); System.out.print(element + " "); System.out.println(); // modify objects being iterated ListIterator litr = al.listiterator(); while(litr.hasnext()) { Object element = litr.next(); litr.set(element + "+"); System.out.print("Modified contents of al: "); itr = al.iterator(); while(itr.hasnext()) { Object element = itr.next(); System.out.print(element + " "); System.out.println(); // now, display the list backwards System.out.print("Modified list backwards: "); while(litr.hasprevious()) { Object element = litr.previous(); System.out.print(element + " "); System.out.println(); The output of this program is shown below: Original contents of al: C A E B D F Modified contents of al: C+ A+ E+ B+ D+ F+ Modified list backwards: F+ D+ B+ E+ A+ C+ Kizito (Makerere University) CSC 1214 February, / 17
Java. Curs 5. Danciu Gabriel Octombrie 2018
Java Curs 5 Danciu Gabriel Octombrie 2018 Colectii java.util Istorie a colectiilor Java Spliterator, PrimitiveIterator JDK 8.0 Dictionary, Vector, Stack, Properties JSE 1.0 Collections, Comparator, HashSet,
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationTop level classes under java.util
collections The java.util package also contains one of Java s most powerful subsystems: the Collections Framework. The Collections Framework is a sophisticated hierarchy of interfaces and classes that
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationChettinad College of Engineering & Technology/II-MCA/ MC9235 Web Programming WEB PROGRAMMING DEPARTMENT OF MCA
WEB PROGRAMMING DEPARTMENT OF MCA Class II MCA Semester III Batch & Year B4 & 2012 Staff A.SALEEM RAJA, MCA.,M.Phil.,M.Tech Prepared by: A.Saleem Raja.,-Asst.Prof MCA pg. 1 UNIT III JAVA FUNDAMENTALS Java
More information6 COMPUTER PROGRAMMING
6 COMPUTER PROGRAMMING ITERATION STATEMENT CONTENTS WHILE DO~WHILE FOR statement 2 Iteration Statement provides While / do-while / For statements for supporting an iteration logic function that the logic
More informationCompSci 125 Lecture 11
CompSci 125 Lecture 11 switch case The? conditional operator do while for Announcements hw5 Due 10/4 p2 Due 10/5 switch case! The switch case Statement Consider a simple four-function calculator 16 buttons:
More information10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS
JAVA CONTROL STATEMENTS Introduction to Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. In Java, control
More informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More informationReview. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char
Review Primitive Data Types & Variables int, long float, double boolean char String Mathematical operators: + - * / % Comparison: < > = == 1 1.3 Conditionals and Loops Introduction to Programming in
More informationCSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:
CSE 20 SAMPLE FINAL Version A Time: 180 minutes Name The following precedence table is provided for your use: Precedence of Operators ( ) - (unary),!, ++, -- *, /, % +, - (binary) = = =,!= &&
More informationChapter 8 Statement-Level Control Structure
Chapter 8 Statement-Level Control Structure To make programs more flexible and powerful: Some means of selecting among alternative control flow paths. Selection statement (conditional statements) Unconditional
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationJava Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.
Loop Control There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first,
More informationNotes on access restrictions
Notes on access restrictions A source code file MyClass.java is a compilation unit and can contain at most one public class. Furthermore, if there is a public class in that file, it must be called MyClass.
More informationComputer Science is...
Computer Science is... Machine Learning Machine learning is the study of computer algorithms that improve automatically through experience. Example: develop adaptive strategies for the control of epileptic
More informationObject Oriented Programming
LAB 8 Part II Arrays Objective This lab focuses on arrays, vectors and related concepts. These are fundamental programming constructs and data structure consisting of related data items. Array An array
More informationCSE 114 Computer Science I
CSE 114 Computer Science I Iteration Cape Breton, Nova Scotia What is Iteration? Repeating a set of instructions a specified number of times or until a specific result is achieved How do we repeat steps?
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More information3-Rewrite the following program code using a Switch statement: 2
PRACTICE PAPER-IP CONVERSION 1-Rewrite the code using switch.case. 2 int a=3; if(a= =3) System.out.println( Number is odd ); if(a= =7) System.out.println( Number is odd ); if(a= =5) System.out.println(
More informationCondi(onals and Loops
Condi(onals and Loops 1 Review Primi(ve Data Types & Variables int, long float, double boolean char String Mathema(cal operators: + - * / % Comparison: < > = == 2 A Founda(on for Programming any program
More informationComplexity of Algorithms
Complexity of Algorithms Time complexity is abstracted to the number of steps or basic operations performed in the worst case during a computation. Now consider the following: 1. How much time does it
More informationBasic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java
Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationUniversity of Palestine. Mid Exam Total Grade: 100
First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative
More informationJava Collections Framework: Interfaces
Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection Interface The List Interface The Iterator Interface The ListIterator
More informationLecture 6 Collections
Lecture 6 Collections Concept A collection is a data structure actually, an object to hold other objects, which let you store and organize objects in useful ways for efficient access Check out the java.util
More informationJava Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition
Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled
More informationComputer Programming I - Unit 5 Lecture page 1 of 14
page 1 of 14 I. The while Statement while, for, do Loops Note: Loop - a control structure that causes a sequence of statement(s) to be executed repeatedly. The while statement is one of three looping statements
More informationJava Basic Programming Constructs
Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This
More informationThe Collections API. Lecture Objectives. The Collections API. Mark Allen Weiss
The Collections API Mark Allen Weiss Lecture Objectives To learn how to use the Collections package in Java 1.2. To illustrate features of Java that help (and hurt) the design of the Collections API. Tuesday,
More informationCP122 CS I. Iteration
CP122 CS I Iteration Tech News! Pix2Pix: machine learning translation of images https://affinelayer.com/pixsrv/ Tech News! Pix2Pix: machine learning translation of images https://affinelayer.com/pixsrv/
More informationAMCAT Automata Coding Sample Questions And Answers
1) Find the syntax error in the below code without modifying the logic. #include int main() float x = 1.1; switch (x) case 1: printf( Choice is 1 ); default: printf( Invalid choice ); return
More informationStrings and Arrays. Hendrik Speleers
Hendrik Speleers Overview Characters and strings String manipulation Formatting output Arrays One-dimensional Two-dimensional Container classes List: ArrayList and LinkedList Iterating over a list Characters
More informationIn Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.
CS101, Mock Boolean Conditions, If-Then Boolean Expressions and Conditions The physical order of a program is the order in which the statements are listed. The logical order of a program is the order in
More informationJava Control Statements
Java Control Statements An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationChapter 10 Collections
Chapter 10 Collections I. Scott MacKenzie 1 Outline 2 1 What is a Collection? A collection is an aggregation with a variable number of components, or elements Examples Portfolio - a collection of Investment
More informationSUN Upgrade for the Sun Certified Java Programmer. SE 6.0. Download Full Version :
SUN 310-066 Upgrade for the Sun Certified Java Programmer. SE 6.0 Download Full Version : https://killexams.com/pass4sure/exam-detail/310-066 Which statement is true about the set variable on line 12?
More informationCSC 1107: Structured Programming
CSC 1107: Structured Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1107
More informationJava Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition
Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled
More informationSchool of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn
CPS109 Course Notes 6 Alexander Ferworn Unrelated Facts Worth Remembering Use metaphors to understand issues and explain them to others. Look up what metaphor means. Table of Contents Contents 1 ITERATION...
More informationImplementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations
Readings List Implementations Chapter 20.2 Objectives Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations Additional references:
More informationDay 2 : Intermediate Concepts 1 Examples
Example1 Day 2 : Intermediate Concepts 1 Examples public class Example1 public static void main(string[] args) int a= 5, b = 10, c = 15, d= 20; Assignment int x = a++; a is assigned to x and then increment
More informationJava Collections. Readings and References. Collections Framework. Java 2 Collections. CSE 403, Spring 2004 Software Engineering
Readings and References Java Collections "Collections", Java tutorial http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Spring 2004 Software Engineering http://www.cs.washington.edu/education/courses/403/04sp/
More informationExpressions & Flow Control
Objectives Distinguish between instance and local variables 4 Expressions & Flow Control Describe how instance variables are initialized Identify and correct a Possible reference before assignment compiler
More informationExam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this
More informationcore programming Basic Java Syntax Marty Hall, Larry Brown:
core programming Basic Java Syntax 1 2001-2003 Marty Hall, Larry Brown: http:// Agenda Creating, compiling, and executing simple Java programs Accessing arrays Looping Using if statements Comparing strings
More informationProgramming in the Small II: Control
Programming in the Small II: Control 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University Agenda Selection
More informationCS8391- OBJECT ORIENTED PROGRAMMING
VELTECH HIGHTECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS8391- OBJECT ORIENTED PROGRAMMING UNIT-1 IINTRODUCTION TO OOP AND JAVA FUNDAMENTALS Object
More informationLast Class. More on loops break continue A bit on arrays
Last Class More on loops break continue A bit on arrays public class February2{ public static void main(string[] args) { String[] allsubjects = { ReviewArray, Example + arrays, obo errors, 2darrays };
More informationANNAMACHARYA INSTITUTE OF TECHNOLOGY AND SCIENCES: : TIRUPATI
ANNAMACHARYA INSTITUTE OF TECHNOLOGY AND SCIENCES: : TIRUPATI Venkatapuram(Village),Renigunta(Mandal),Tirupati,Chitoor District, Andhra Pradesh-517520. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING NAME
More informationFirst Name Last Name ID#
CIS 265 Sect 01 - V. Matos Exam-2 Spring-2015 First Name Last Name ID# (15 pts) MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) In the following
More informationPrinciples of Computer Science
Principles of Computer Science Lecture 2 Dr. Horia V. Corcalciuc Horia Hulubei National Institute for R&D in Physics and Nuclear Engineering (IFIN-HH) January 27, 2016 Loops: do-while do-while loops do
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationInterfaces, collections and comparisons
תכנות מונחה עצמים תרגול מספר 4 Interfaces, collections and comparisons Interfaces Overview Overview O Interface defines behavior. Overview O Interface defines behavior. O The interface includes: O Name
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationAP Computer Science A Summer Assignment 2017
AP Computer Science A Summer Assignment 2017 The objective of this summer assignment is to ensure that each student has the ability to compile and run code on a computer system at home. We will be doing
More informationSELECTION STATEMENTS:
UNIT-2 STATEMENTS A statement is a part of your program that can be executed. That is, a statement specifies an action. Statements generally contain expressions and end with a semicolon. Statements that
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write
More informationOverview of Java s Support for Polymorphism
Overview of Java s Support for Polymorphism Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt
More informationITERATION WEEK 4: EXMAPLES IN CLASS
Monday Section 2 import java.util.scanner; public class W4MSection2 { ITERATION WEEK 4: EXMAPLES IN CLASS public static void main(string[] args) { Scanner input1 = new Scanner (System.in); int CircleCenterX
More informationChapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition
Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition 5.2 Q1: Counter-controlled repetition requires a. A control variable and initial value. b. A control variable
More informationCOMPUTER PROGRAMMING LOOPS
COMPUTER PROGRAMMING LOOPS http://www.tutorialspoint.com/computer_programming/computer_programming_loops.htm Copyright tutorialspoint.com Let's consider a situation when you want to write five times. Here
More informationCSEN 202 Introduction to Computer Programming
CSEN 202 Introduction to Computer Programming Lecture 4: Iterations Prof. Dr. Slim Abdennadher and Dr Mohammed Abdel Megeed Salem, slim.abdennadher@guc.edu.eg German University Cairo, Department of Media
More informationAbstract data types (again) Announcements. Example ADT an integer bag (next) The Java Collections Framework
Announcements Abstract data types (again) PS 5 ready Tutoring schedule updated with more hours Today s topic: The Java Collections Framework Reading: Section 7.5 An ADT is a model of a collection of data
More informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar 2018
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationCS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam
Seat Number Name CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam This is a closed book exam. Answer all of the questions on the question paper in the space provided. If
More informationCS171:Introduction to Computer Science II
CS171:Introduction to Computer Science II Department of Mathematics and Computer Science Li Xiong 9/7/2012 1 Announcement Introductory/Eclipse Lab, Friday, Sep 7, 2-3pm (today) Hw1 to be assigned Monday,
More informationOutline. Part 6. Trees (1) Data RepresentaCon. Terminology 3/2/12. Represent hierarchical relationships B C D. Parent node
Outline Part 6. Trees (1) CS 200 lgorithms and Data Structures Terminology Binary Tree Basic operations Traversals of a Binary Tree Representations of a Binary Tree Implementations Binary Search Tree lgorithms
More informationObject-oriented programming in...
Programming Languages Week 12 Object-oriented programming in... College of Information Science and Engineering Ritsumeikan University plan this week intro to Java advantages and disadvantages language
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationRepetition, Looping. While Loop
Repetition, Looping Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationInstructor: Eng.Omar Al-Nahal
Faculty of Engineering & Information Technology Software Engineering Department Computer Science [2] Lab 6: Introduction in arrays Declaring and Creating Arrays Multidimensional Arrays Instructor: Eng.Omar
More informationFlow Control. Key Notion. Statement Categories. 28-Oct-10
Boaz Kantor Introduction to Computer Science, Fall semester 2010-2011 IDC Herzliya Flow Control Raistlin: This alters time. Astinus: This alters nothing...time flows on, undisturbed. Raistlin: And carries
More informationJAVA EXAMPLES - SOLVING DEADLOCK
JAVA EXAMPLES - SOLVING DEADLOCK http://www.tutorialspoint.com/javaexamples/thread_deadlock.htm Copyright tutorialspoint.com Problem Description: How to solve deadlock using thread? Solution: Following
More information3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)
Structures Programming in C++ Sequential Branching Repeating Loops (Repetition) 2 1 Loops Repetition is referred to the ability of repeating a statement or a set of statements as many times this is necessary.
More informationCHAPTER 5 FLOW OF CONTROL
CHAPTER 5 FLOW OF CONTROL PROGRAMMING CONSTRUCTS - In a program, statements may be executed sequentially, selectively or iteratively. - Every programming language provides constructs to support sequence,
More informationCSE 143 Lecture 14. Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4
CSE 143 Lecture 14 Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Related classes Consider classes for
More informationDecision Making and Loops
Decision Making and Loops Goals of this section Continue looking at decision structures - switch control structures -if-else-if control structures Introduce looping -while loop -do-while loop -simple for
More informationd. If a is false and b is false then the output is "ELSE" Answer?
Intermediate Level 1) Predict the output for the below code: public void foo( boolean a, boolean b) if( a ) System.out.println("A"); if(a && b) System.out.println( "A && B"); if (!b ) System.out.println(
More informationCHAPTER : 9 FLOW OF CONTROL
CHAPTER 9 FLOW OF CONTROL Statements-Statements are the instructions given to the Computer to perform any kind of action. Null Statement-A null statement is useful in those case where syntax of the language
More informationFor that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.
Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification
More informationCONDITIONAL EXECUTION: PART 2
CONDITIONAL EXECUTION: PART 2 yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Review: The if-else statement The switch statement A look
More information1. Find the output of following java program. class MainClass { public static void main (String arg[])
1. Find the output of following java program. public static void main(string arg[]) int arr[][]=4,3,2,1; int i,j; for(i=1;i>-1;i--) for(j=1;j>-1;j--) System.out.print(arr[i][j]); 1234 The above java program
More informationRecitation: Loop Jul 7, 2008
Nested Loop Recitation: Loop Jul 7, 2008 1. What is the output of the following program? Use pen and paper only. The output is: ****** ***** **** *** ** * 2. Test this program in your computer 3. Use "for
More informationG51PRG: Introduction to Programming Second semester
G51PRG: Introduction to Programming Second semester Lecture 7 Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous lecture es interfaces collections hierarchy in Java Lecture 7:
More informationIntroduction to the Java Basics: Control Flow Statements
Lesson 3: Introduction to the Java Basics: Control Flow Statements Repetition Structures THEORY Variable Assignment You can only assign a value to a variable that is consistent with the variable s declared
More informationJava Programming: from the Beginning. Chapter 8 More Control Structures. CSc 2310: Principle of Programming g( (Java) Spring 2013
CSc 2310: Principle of Programming g( (Java) Spring 2013 Java Programming: from the Beginning Chapter 8 More Control Structures 1 Copyright 2000 W. W. Norton & Company. All rights reserved. 81 8.1 Exceptions
More informationSAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1
FACULTY OF SCIENCE AND TECHNOLOGY SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1 ACADEMIC SESSION 2014; SEMESTER 3 PRG102D: BASIC PROGRAMMING CONCEPTS Section A Compulsory section Question
More informationMichele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring
Michele Van Dyne Museum 204B mvandyne@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II, Spring 2016 1 Review of Java Basics Data Types Arrays NEW: multidimensional
More informationComputer Programming, I. Laboratory Manual. Experiment #6. Loops
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #6
More informationFlow Control. Boaz Kantor Introduction to Computer Science, Fall semester IDC Herzliya
Boaz Kantor Introduction to Computer Science, Fall semester 2010-2011 IDC Herzliya Flow Control Raistlin: This alters time. Astinus: This alters nothing...time flows on, undisturbed. Raistlin: And carries
More informationCollections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock)
Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections
More informationLecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map
Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections
More informationGlossary. (Very) Simple Java Reference (draft, v0.2)
(Very) Simple Java Reference (draft, v0.2) (Very) Simple Java Reference (draft, v0.2) Explanations and examples for if and for (other things to-be-done). This is supposed to be a reference manual, so we
More information1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1
Ba Arrays Arrays A normal variable holds value: An array variable holds a collection of values: 4 Naming arrays An array has a single name, so the elements are numbered or indexed. 0 3 4 5 Numbering starts
More information