CS 240 – Computer Programming I Lab Kalpa Gunaratna –

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

Introduction to Programming
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
CS107 Introduction to Computer Science Lecture 2.
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
Session Objectives# 24 COULD code the solution for an algorithm
1 Control Structures (and user input). 2 Flow of Control The order statements are executed is called flow of control By default, statements in a method.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
Designing Algorithms February 2nd. Administrativia Lab assignments will be due every Monday Lab access –Searles 128: daily until 4pm unless class in progress.
CS107 Introduction to Computer Science Lecture 2.
Designing Algorithms Csci 107 Lecture 3. Administrativia Lab access –Searles 128: daily until 4pm unless class in progress –Searles 117: 6-10pm, Sat-Sun.
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Review Algorithm Analysis Problem Solving Space Complexity
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
COMP 1001: Introduction to Computers for Arts and Social Sciences Programming in Scratch Monday, May 16, 2011.
Methods (Functions) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CHAPTER 4: CONDITIONAL STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CSE 102 Introduction to Computer Engineering What is an Algorithm?
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CPSC 171 Introduction to Computer Science Algorithm Discovery and Design.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
Basic Control Structures
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
The Hashemite University Computer Engineering Department
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CSE 110 Midterm Review Hans and Carmine. If Statements If statements use decision logic In order to properly use if statements relational operators must.
CS 241 – Computer Programming II Lab
CS 240 – Computer Programming I Lab
CSC111 Quick Revision.
CS 240 – Computer Programming I Lab
Chapter 3 Edited by JJ Shepherd
Chapter 6 More Conditionals and Loops
SELECTION STATEMENTS (1)
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Computers & Programming Languages
Computers & Programming Languages
Lec 4: while loop and do-while loop
Selection Statements.
Computer Science Core Concepts
Flowcharts and Pseudo Code
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 14, 2011
Repetition Statements
CSC 1051 – Data Structures and Algorithms I
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Presentation transcript:

CS 240 – Computer Programming I Lab Kalpa Gunaratna –

Contact  Contact by   Office hours  376 Joshi  Mondays & Wednesday 3:00 pm – 4:00 pm

Get input from key board  Scanner keyboard = new Scanner(System.in);  keyboard is the given name to the variable here. You can use any name you like. Object typenameCreate new object and assign to name

Useful Arithmetic & Relational operators  > greater than, = greater than or equal to, <= less than or equal to, etc.  Example: 5 > 6 will output false. Number 5 is not greater than 6.  Boolean operators  && - logical AND  || - logical OR  Example: x==5 && y<5, this expression outputs true if and only if value of x is 5 and value of y is less than 5.

If statements  Syntax  if ( ) { runs if is true } else { runs if is false }

If else if … if( ) { your code here } else if( ) { your code here } else { your code here }

Print statements  System.out.print()  Prints a line and stays in the current line  Sytem.out.println()  Prints a line and goes to a new line  System.out.printf(“ ”, )  Ex: System.out.printf(“%.2f \n", );

Pseudo Code  Not a Java code or any programming language  Human readable code similar to a programming language.  Uses to describe algorithms.  Example:  Algorithm – if input value is greater than 5, out put to the console a success message. Otherwise exit program.  Pseudo Code –  Get user input value x. if x is greater than 5 then out put to console “Success” else exit from program  You see that pseudo code has nothing to do with Java!  More examples : 

Flow Chart  Condition  Statement input true false

 Example If then else

sum = 0 count = 1 REPEAT IF count is even THEN sum = sum + count count = count + 1 UNTIL count > 20 DISPLAY sum Pseudo code Flow chart

 You can find useful information and helpful tips about flow charts at, 