CS 101 Computer Programming
|
|
- Reynard Reynolds
- 6 years ago
- Views:
Transcription
1 CS 101 Computer Programming Statements Review
2 Variables Declare once, use multiple times, support variations Use meaningfull names with appropriate length Case sensitive, e.g., speed, currentcoursecode, carlength Start with a letter, cannot be a keyword (int) Constants, e.g., NUM_RECTANGLES Make use of arithmetic operations (- + / *) int x = 10; int h = 50; GRect r1 = new GRect(x, 10, 50, h); GRect r2 = new GRect(x+10, 20, 50, h); GRect r3 = new GRect(x+20, 30, 50, h); GRect r4 = new GRect(x+30, 40, 50, h); add(r1); add(r2); add(r3); add(r4); CS 101 Özyeğin University 2
3 Order Of Execution public class Squares extends GraphicsProgram { public void run() { int x = 10; GRect r1 = new GRect(x, 10, SIZE, SIZE); GRect r2 = new GRect(x+10, 20, SIZE, SIZE); GRect r3 = new GRect(x+20, 30, SIZE, SIZE); GRect r4 = new GRect(x+30, 40, SIZE, SIZE); add(r1); add(r2); add(r3); add(r4); private static final int SIZE = 50; variable definitions in the class run() CS 101 Özyeğin University
4 Order Of Execution public class Squares extends GraphicsProgram { public void run() { int x = 10; GRect r1 = new GRect(x, 10, SIZE, SIZE); GRect r2 = new GRect(x+10, 20, SIZE, SIZE); GRect r3 = new GRect(x+20, 30, SIZE, SIZE); GRect r4 = new GRect(x+30, 40, SIZE, SIZE); add(r1); add(r2); add(r3); add(r4); private static final int SIZE = 50; variable definitions in the class run() CS 101 Özyeğin University
5 Order of statements Order of method run and variable declarations does not matter Order of statements within the run method does matter public class Squares extends GraphicsProgram { private static final int SIZE = 50; public void run() { int x = 10; GRect r1 = new GRect(x, 10, SIZE, SIZE); GRect r2 = new GRect(x+10, 20, SIZE, SIZE); GRect r3 = new GRect(x+20, 30, SIZE, SIZE); GRect r4 = new GRect(x+30, 40, SIZE, SIZE); add(r1); add(r2); add(r3); add(r4); Özyeğin University CS 101 Computer Programming 5
6 Conditional Selection if(condition) { dosomething; dootherstuff; true condition false dosomething dootherstuff CS 101 Özyeğin University
7 Conditional Selection if(condition) { dosomething; else { dosomethingelse; dootherstuff; true dosomething condition false dosomethingelse dootherstuff CS 101 Özyeğin University
8 Boolean Expressions as Conditions x is 3, y is 5. Expression Value x - y > 0 false (x % 2) == 0 false ((x+1) % 2) == 0 true x + y >= 8 true!(y x > 0) false
9 Example: logical operators if (x == 10 && y == 20) {... if (x == 10 y == 20) {... CS 101 Özyeğin University
10 Common mistakes 0 < x < 5 error You should use 0 < x && x < 5 Use == for comparison, not =. The latter is for assignment. =< and => are syntax errors. Do not use & or instead of && and. & and are bitwise And and Or operators. Do not use == to compare floating point numbers (because float representation is not exact. Use >= and <= instead) CS 101 Özyeğin University
11 Exercise Does the following boolean expression evaluate to true or false? Assume x is 10, y is (x > 0 && x < 100) y > 1000 CS 101 Özyeğin University 11
12 Exercise Does the following boolean expression evaluate to true or false? Assume x is 10, y is (x > 0 && x < 100) y > 1000 true true true false true CS 101 Özyeğin University 12
13 Boolean Variables Datatype for the Boolean values true and false. Common to use with control statements to determine the flow of a program boolean condition = true; boolean isbigger = (x > y);... if(condition && isbigger) {... CS 101 Özyeğin University
14 Exercise What would be the output of the following? boolean draw = false; if (!draw) { GRect rect = new GRect(30, 20, 50, 50); add(rect); draw = true; if (draw) { GLine line1 = new GLine(20, 10, 90, 80); GLine line2 = new GLine(20, 80, 90, 10); add(line1); add(line2); CS 101 Özyeğin University 14
15 Exercise What would be the output of the following? boolean draw = false; if (!draw) { GRect rect = new GRect(30, 20, 50, 50); add(rect); draw = true; if (draw) { GLine line1 = new GLine(20, 10, 90, 80); GLine line2 = new GLine(20, 80, 90, 10); add(line1); add(line2); CS 101 Özyeğin University 15
16 Loops while(condition) { dosomething domorestuff condition true false dosomething domorestuff CS 101 Özyeğin Üniversitesi
17 Example: boolean variables boolean screenborderreached = false; int y = 0; while(!screenborderreached) { GLine line = new GLine(0, y, getwidth(), y); add(line); y = y + 10; if(y > getheight()) { screenborderreached = true; CS 101 Özyeğin University
18 boolean screenborderreached = false; int y = 0; Example while(!screenborderreached) { GLine line = new GLine(0, y, getwidth(), y); if(y > getheight()/4 && y < (getheight()/4)*3) { line.setcolor(color.red); else { line.setcolor(color.green); add(line); y = y + 10; if(y > getheight()) { screenborderreached = true; CS 101 Özyeğin University
19 Nested if s if, if-else statements can be nested within each other if (<condition>) { if(<another condition>) {... else {... if(<yet another condition>) {... CS 101 Özyeğin University
20 1 Example: equivalent results 2 if(y > getheight()/4 && y < (getheight()/4)*3) { line.setcolor(color.red); else { line.setcolor(color.green); 3 if(y > getheight()/4) { if(y < (getheight()/4)*3) { line.setcolor(color.red); else { line.setcolor(color.green); else { line.setcolor(color.green); 4 line.setcolor(color.green); if(y > getheight()/4) { if(y < (getheight()/4)*3) { line.setcolor(color.red); line.setcolor(color.green); if(y > getheight()/4 && y < (getheight()/4)*3) { line.setcolor(color.red); CS 101 Özyeğin University
21 Nested loops int x = 0; while (x < 100) { int y = 0; while(y < 100) { GRect rect = new GRect(x, y, 10, 10); add(rect); y = y + 10; x = x + 10; CS 101 Özyeğin University 21
22 Exercise Modify the program to come up with the result below int x = 0; while (x < 100) { int y = 0; while(y < 100) { GRect rect = new GRect(x, y, 10, 10); /* TODO:??? */ add(rect); y = y + 10; x = x + 10; CS 101 Özyeğin University 22
23 Exercise int x = 0; while (x < 100) { int y = 0; while(y < 100) { GRect rect = new GRect(x, y, 10, 10); if(x > 30 && x < 60 && y > 30 && y < 60) { rect.setfilled(true); rect.setfillcolor(color.red); add(rect); y = y + 10; x = x + 10; CS 101 Özyeğin University 23
24 for vs. while The for statement for ( init ; test ; step ) { statements to be repeated is functionally equivalent to the following code using while: init; while ( test ) { statements to be repeated step; The advantage of the for statement is that everything you need to know to understand how many times the loop will run is explicitly included in the header line.
25 Nested for Statements The body of a control statement can contain other statements. Such statements are said to be nested. Many applications require nested for statements. The next slide, for example, shows a program to display a standard checkerboard in which the number of rows and number of columns are given by the constants N_ROWS and N_COLUMNS. The for loops in the Checkerboard program look like this: for (int i = 0; i < N_ROWS; i++) { for (int j = 0; j < N_COLUMNS; j++) { Display the square at row i and column j. Because the entire inner loop runs for each cycle of the outer loop, the program displays N_ROWS x N_COLUMNS squares.
26 The Checkerboard Program public void run() { double sqsize = (double) getheight() / N_ROWS; for (int i = 0; i < N_ROWS; i++) { for (int j = 0; j < N_COLUMNS; j++) { double x = j * sqsize; double y = i * sqsize; GRect sq = new GRect(x, y, sqsize, sqsize); sq.setfilled((i + j) % 2!= 0); add(sq); sqsize i j x y Execute these inner statements loop six seven more times to complete the checkerboard. row. sq Checkerboard skip simulation
27 The End
Programming Lecture 4
Five-Minute Review 1. What are classes and objects? What is a class hierarchy? 2. What is an expression? A term? 3. What is a variable declaration? 4. What is an assignment? What is precedence? 5. What
More informationProgramming Lecture 4
Five-Minute Review 1. What are classes and objects? What is a class hierarchy? 2. What is an expression? A term? 3. What is a variable declaration? 4. What is an assignment? What is precedence? 5. What
More informationProgramming Lecture 4
Five-Minute Review 1. What is a class hierarchy? 2. Which graphical coordinate system is used by Java (and most other languages)? 3. Why is a collage a good methapher for GObjects? 4. What is a CFG? What
More informationProgramming Lecture 4
Five-Minute Review 1. What is a class hierarchy? 2. Which graphical coordinate system is used by Java (and most other languages)? 3. Why is a collage a good methapher for GObjects? 4. What is a CFG? What
More informationNested Loops Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University
Nested Loops Chris Piech CS106A, Stanford University By Chris Once upon a time X was looking for love! int x = 5; if(lookingforlove()) { int y = 5; println(x + y); 5 x X was looking for love! int x =
More informationSimple Java YEAH Hours. Brahm Capoor and Vrinda Vasavada
Simple Java YEAH Hours Brahm Capoor and Vrinda Vasavada What are YEAH hours? Held soon after each assignment is released Help you to get an early start on your assignments Future dates TBA Slides will
More informationCS 106A, Lecture 11 Graphics
CS 106A, Lecture 11 Graphics reading: Art & Science of Java, 9.1-9.3 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All
More informationSolutions for Section #2
Chris Piech Handout #12A CS 106A January 25, 2017 Solutions for Section #2 1. The Fibonacci sequence Portions of this handout by Eric Roberts and Jeremy Keeshin * File: Fibonacci.java * --------------------
More informationSolutions for Section #2
Chris Piech Section #2 CS 106A January 24, 2018 Solutions for Section #2 1. The Fibonacci sequence Portions of this handout by Eric Roberts and Jeremy Keeshin * File: Fibonacci.java * This program lists
More informationAnswers to Additional Practice Final Problems
Handout #36A CS 106A Aug 11, 2011 Answers to Additional Practice Final Problems Problem Interactors public class InteractorsSample extends GraphicsProgram{ private GLine fwdslash; private GLine backslash;
More informationControl Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003
Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an
More informationScore score < score < score < 65 Score < 50
What if we need to write a code segment to assign letter grades based on exam scores according to the following rules. Write this using if-only. How to use if-else correctly in this example? score Score
More informationCHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++
CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,
More informationCMSC 113: Computer Science I Review Questions for Exam #1
CMSC 113: Computer Science I Review Questions for Exam #1 During the actual exam, you will have access to whatever printed resources you like, but no electronic resources of any sort. Part I. Each of the
More informationObjects and Graphics
Objects and Graphics One Last Thought on Loops... Looping Forever while loops iterate as long as their condition evaluates to true. A loop of the form while (true) will loop forever (unless something stops
More informationSolutions for Section #4
Colin Kincaid Section #4 CS 106A July 20, 2018 Solutions for Section #4 1. Warmup: Parameters (MakeBoxes) Portions of this handout by Eric Roberts, Marty Stepp, Chris Piech, Ruchir Rastogi, and Guy Blanc
More informationPrepared by: Shraddha Modi
Prepared by: Shraddha Modi Introduction In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop consist of two segments Body of
More informationPrimitives, Objects, and Heap/Stack Review 1 Chris Piech CS106A, Stanford University
Primitives, Objects, and Heap/Stack Review 1 Chris Piech CS106A, Stanford University 1 Plan for today Announcements/Exam logistics Tracing 1D Arrays 2D Arrays ArrayList Plan for tomorrow Announcements/Exam
More informationChapter 4: Control structures. Repetition
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationFile: GFace.java /* * File: GFace.java * This class implements a face as a GCompound. */
Steve Cooper Handout #22 CS 106A April 24, 2013 Graphics and Events Examples File: GFace.java * File: GFace.java * This class implements a face as a GCompound. // Note: only need acm.graphics since this
More informationCS 106A Midterm Review. Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017
+ CS 106A Midterm Review Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017 Details n Only the textbook is allowed n n n The Art and Science of Java Karel Course Reader You will
More informationExpressions, Statements, and Control Structures
Expressions, Statements, and Control Structures Announcements Assignment 2 out, due next Wednesday, February 1. Explore the Java concepts we've covered and will be covering. Unleash your creative potential!
More informationChapter 4: Control structures
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationIteration in Programming
Iteration in Programming for loops Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list There are three types of loop in programming: While
More informationCS 106A, Lecture 23 Interactors and GCanvas
CS 106A, Lecture 23 Interactors and GCanvas suggested reading: Java Ch. 10.5-10.6 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5
More informationAssignment: 1. (Unit-1 Flowchart and Algorithm)
Assignment: 1 (Unit-1 Flowchart and Algorithm) 1. Explain: Flowchart with its symbols. 2. Explain: Types of flowchart with example. 3. Explain: Algorithm with example. 4. Draw a flowchart to find the area
More informationCS251L REVIEW Derek Trumbo UNM
CS251L REVIEW 2010.8.25 Derek Trumbo UNM Java Applications Java application defined by a Java class with a main method public static void main(string[] args) args is an array of strings represented the
More informationDrawing Geometrical Objects. Graphic courtesy of Eric Roberts
Methods Drawing Geometrical Objects Graphic courtesy of Eric Roberts Drawing Geometrical Objects Constructors new GRect( x, y, width, height) Creates a rectangle whose upper left corner is at (x, y) of
More informationMemory Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University
Memory Chris Piech CS106A, Stanford University Learning Goals 1. Be able to trace memory with references Write this program Who thinks this prints true? Who thinks this prints true? public void run() {
More informationGetting Familiar with ACM_JTF
Getting Familiar with ACM_JTF PART1: Introduction to the JTF Packages In early 2004, the ACM created the Java Task Force (JTF) to review the Java language, APIs, and tools from the perspective of introductory
More informationExample: Monte Carlo Simulation 1
Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149
More informationAPCS Semester #1 Final Exam Practice Problems
Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester
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 informationCS 106A, Lecture 14 Events and Instance Variables
CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons
More informationEMBEDDED SYSTEMS PROGRAMMING Language Basics
EMBEDDED SYSTEMS PROGRAMMING 2014-15 Language Basics (PROGRAMMING) LANGUAGES "The tower of Babel" by Pieter Bruegel the Elder Kunsthistorisches Museum, Vienna ABOUT THE LANGUAGES C (1972) Designed to replace
More informationCS106A Review Session
CS106A Review Session Nick Troccoli This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved. Based on slides
More informationFor loops, nested loops and scopes. Jordi Cortadella Department of Computer Science
For loops, nested loops and scopes Jordi Cortadella Department of Computer Science Outline For loops Scopes Nested loops Introduction to Programming Dept. CS, UPC 2 Calculate x y Algorithm: repeated multiplication
More informationFlow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch
Flow of Control True and False in C Conditional Execution Iteration Nested Code(Nested-ifs, Nested-loops) Jumps 1 True and False in C False is represented by any zero value The int expression having the
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 informationCS 106A, Lecture 14 Events and Instance Variables
CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons
More informationProgramming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur
Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur Lecture 04 Demonstration 1 So, we have learned about how to run Java programs
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationInteractors. Brahm Capoor.
Interactors Brahm Capoor brahm@stanfordedu Learning goals for today To learn how to use interactors in our programs Learning goals for today To learn how to use interactors in our programs To go under
More informationNested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.
Nested Loops To investigate nested loops, we'll look at printing out some different star patterns. Let s consider that we want to print out a square as follows: We know we can print out one line of this
More informationOutline. For loops, nested loops and scopes. Calculate x y. For loops. Scopes. Nested loops. Algorithm: repeated multiplication x x x x
Outline For loops, nested loops and scopes For loops Scopes Jordi Cortadella Department of Computer Science Nested loops Calculate x y Algorithm: repeated multiplication x x x x y times y x i p=x i 4 3
More informationAssignment 6 YEAH Hours. Ben Barnett and Avery Wang
Assignment 6 YEAH Hours Ben Barnett and Avery Wang 2 Overview 1. Review relevant material. 2. Discuss each milestone. 3. Q&A Classes Define your very own variable type! 4 What custom variables have you
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 informationNumerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2
Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.
More informationCS 106A, Lecture 24 Interactors and NameSurfer
CS 106A, Lecture 24 Interactors and NameSurfer suggested reading: Java Ch. 10.5-10.6 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationFRAC: Language Reference Manual
FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer
More informationClasses. How can we manage large programs?
Classes How can we manage large programs? GRect: keeps track of x, y, width, height, color, visibility ArrayList: Maintains a list of elements (under the hood, it manages an array for you) String: stores
More informationKingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS
Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Objectives By the end of this section you should be able to:
More information1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?
1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity
More informationAdapted from slides by Brahm Capoor. Breakout YEAH hours. Michael (Chung Troute)
Adapted from slides by Brahm Capoor Breakout YEAH hours Michael (Chung Troute) Road Map Lecture Review Graphics Animation Events Using the debugger Assignment Overview Q&A! Graphics GRect rect = new GRect(50,
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationComputational Expression
Computational Expression Do While Loop, For Loop, Arrays Janyl Jumadinova 26 November, 2018 Janyl Jumadinova Computational Expression 26 November, 2018 1 / 18 Review: Repetition structures while() loop
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG 1 Notice Prepare the Weekly Quiz The weekly quiz is for the knowledge we learned in the previous week (both the
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationCSE 142 Su 04 Computer Programming 1 - Java. Objects
Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request
More informationAdvanced Computer Programming
Hazırlayan Yard. Doç. Dr. Mehmet Fidan WHILE, DO-WHILE and FOR LOOPS Loops are used for executing code blocks repeatedly. Decision of continuing loop is given by boolean expression. If boolean expression
More informationCSE 130 Introduction to Programming in C Control Flow Revisited
CSE 130 Introduction to Programming in C Control Flow Revisited Spring 2018 Stony Brook University Instructor: Shebuti Rayana Control Flow Program Control Ø Program begins execution at the main() function.
More informationCS106A Review Session. Monday Oct. 31, 2016 Nick Troccoli
CS106A Review Session Monday Oct. 31, 2016 Nick Troccoli 1 Topic List Karel Java constructs Graphics + Animation Classes and Interfaces Memory (Pass-by-reference vs. pass by value) Event-driven programming
More informationWhat is Java? professional software engineering.
Welcome Back! Welcome to Java! What is Java? Java is an industrial programming language used to build large applications. Used in web servers, Android phones, desktop applications, etc. Extremely common:
More information1/31/2017. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Expressions are Used to Perform Calculations Let s talk in more detail starting
More information9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Expressions are Used to Perform Calculations Let s talk in more detail starting
More informationMultiple-Subscripted Arrays
Arrays in C can have multiple subscripts. A common use of multiple-subscripted arrays (also called multidimensional arrays) is to represent tables of values consisting of information arranged in rows and
More informationUnit 3 Decision making, Looping and Arrays
Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.
More informationCS302 - Data Structures using C++
CS302 - Data Structures using C++ Pre-Course: Variables, Basic Types, Control Structures Kostas Alexis Slides inspired by the course Modern C++, Uni Bonn: http://www.ipb.uni-bonn.de/teaching/modern-cpp/
More informationAll copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva
All copyrights reserved - KV NAD, Aluva Dinesh Kumar Ram PGT(CS) KV NAD Aluva Overview Looping Introduction While loops Syntax Examples Points to Observe Infinite Loops Examples using while loops do..
More informationDecision Making in C
Decision Making in C Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More informationn Group of statements that are executed repeatedly while some condition remains true
Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,
More informationReminder the scope of a variable is the part of the program where that variable is visible Will this compile?
CS139 Nested Loops Loops and Scope Reminder the scope of a variable is the part of the program where that variable is visible Will this compile? while (number < 10) { String result = "latest " + number;
More informationLesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing
More informationThe Basic Parts of Java
Data Types Primitive Composite The Basic Parts of Java array (will also be covered in the lecture on Collections) Lexical Rules Expressions and operators Methods Parameter list Argument parsing An example
More informationYour first C++ program
Your first C++ program #include using namespace std; int main () cout
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #16 Loops: Matrix Using Nested for Loop In this section, we will use the, for loop to code of the matrix problem.
More informationPDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs
PDS Lab Section 16 Autumn-2017 Tutorial 3 C Programming Constructs This flowchart shows how to find the roots of a Quadratic equation Ax 2 +Bx+C = 0 Start Input A,B,C x B 2 4AC False x If 0 True B x 2A
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationSolutions to Midterm Exam
Nick Troccoli Midterm Solutions CS 106A August 2, 2017 Solutions to Midterm Exam Problem 1: Karel the Robot public class FarmerKarel extends SuperKarel { checkrow(); while (leftisclear()) { movetonextrow();
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions
More informationComputing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer
Computing Science 114 Solutions to Midterm Examination Tuesday October 19, 2004 INSTRUCTOR: I E LEONARD TIME: 50 MINUTES In Questions 1 20, Circle EXACTLY ONE choice as the best answer 1 [2 pts] What company
More informationRepetition with for loops
Repetition with for loops So far, when we wanted to perform a task multiple times, we have written redundant code: System.out.println( Building Java Programs ); // print 5 blank lines System.out.println(
More informationPIC 10A. Review for Midterm I
PIC 10A Review for Midterm I Midterm I Friday, May 1, 2.00-2.50pm. Try to show up 5 min early so we can start on time. Exam will cover all material up to and including todays lecture. (Only topics that
More informationObject Oriented Programming Lecture (2.1) Supervisor Ebtsam AbdelHakam Department of Computer Science Najran University
Object Oriented Programming Lecture (2.1) Supervisor Ebtsam AbdelHakam ebtsamabd@gmail.com Department of Computer Science Najran University Ebtsam AbdelHakam 1 Outline 2 Operators Arithmetic Operators.
More informationegrapher Language Reference Manual
egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction
More informationLAB 5: SELECTION STATEMENTS
Statement Purpose: The purpose of this lab is to familiarize students with Conditional statements and explain how to control the sequence of statement execution, depending on the value of an expression
More informationGive one example where you might wish to use a three dimensional array
CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming
More informationBinghamton University. CS-140 Fall Data Types in Java
Data Types in Java 1 CS-211 2015 Example Class: Car How Cars are Described Make Model Year Color Owner Location Mileage Actions that can be applied to cars Create a new car Transfer ownership Move to a
More informationPROGRAMMING. We create identity
2 PROGRAMMING We create identity TOPICS COVERED Getting Started Setup and draw Variables mousex, mousey other system variables variable declaration types Arithmetic Predefined methods abs, max, delay Topics
More informationStructured Programming. Dr. Mohamed Khedr Lecture 9
Structured Programming Dr. Mohamed Khedr http://webmail.aast.edu/~khedr 1 Two Types of Loops count controlled loops repeat a specified number of times event-controlled loops some condition within the loop
More informationCS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their
More informationDept. of CSE, IIT KGP
Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of
More informationCHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS
CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS Computers process information and usually they need to process masses of information. In previous chapters we have studied programs that contain a few variables
More informationCS 101 Computer Programming
CS 101 Computer Programming Methods (Chapter 5) Özyeğin University slides partially adapted from UW CSE 142 course slides Remember? Control Flow: the order in which statements are executed CS 101 Özyeğin
More informationLecture 5 Tao Wang 1
Lecture 5 Tao Wang 1 Objectives In this chapter, you will learn about: Selection criteria Relational operators Logical operators The if-else statement Nested if statements C++ for Engineers and Scientists,
More information