200 300 400 500 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100 Expressions Methods if else Statements Loops Potpourri.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Programming Languages and Paradigms The C Programming Language.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
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.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Loops –For For Reading for this Lecture, L&L, Part of 5.8.
PSU CS 106 Computing Fundamentals II VB Statements HM 5/19/2008.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Thirteen conditional expressions: letting programs make “decisions”
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Geography 465 Assignments, Conditionals, and Loops.
1 Chapter 4 Simple Selections and Repetitions INTRODUCTION The majority of challenging and interesting algorithms necessitate the ability to make.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 5: Program Logic and Indefinite Loops.
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.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Chapter 4: Control Structures II
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Final Jeopardy Fundamen tal Java Numerical Data type Boolean Expressi on If/THEN/ WHILE Miscellan eous
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
CMSC 150 LOOPS CS 150: Fri 20 Jan Representing DNA AGTCCAGTGTCAA.
A High Flying Overview CS139 – Fall 2006 How far we have come.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
A High Flying Overview CS139 – Fall 2010 How far we have come.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
Test 2 Review Outline.
Exam 2 Review.
Chapter 5: Control Structures II (Repetition)
Chapter 3: Decisions and Loops
Chapter 6 More Conditionals and Loops
CMPT 201 Functions.
Repetition-Sentinel,Flag Loop/Do_While
SELECTION STATEMENTS (1)
CS139 – Fall 2010 How far we have come
Computers & Programming Languages
An Introduction to Java – Part I, language basics
Pages:51-59 Section: Control1 : decisions
Introduction to Programming Using Python PART 2
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Logical Operators and While Loops
Flow of Control.
Seating “chart” Front - Screen rows Back DOOR.
Names of variables, functions, classes
Question 1a) What is printed by the following Java program? int s;
Pages:51-59 Section: Control1 : decisions
Presentation transcript:

Expressions Methods if else Statements Loops Potpourri

8 % 20

8

((20 % 8) / 3) * (20 / 8)

2

15 >= 7 >= 0

INVALID

(15 >= 7) && !true

false

(23 / 7 > 2) || (23 % 7 > 2)

true

This line contains a method return type.

45

This line contains a formal parameter

5 or 45

This is the name of one formal parameter.

args, word, letter

This line contains an actual parameter (argument).

15, 20, 22, 27-28, 32, 34, 36, 39, 51

This is one of those actual parameters (arguments)

System.in, any of the output, count, letter, “Y”, pos

T/F, An if statement must contain an else clause.

F

This line contains a boolean expression.

18, 25, 39, 49, 51

This is a boolean expression that will evaluate to true if an integer, num1, is evenly divisible by 5 and false otherwise. This is a boolean expressi o n that will evaluate to This expression evaluates to true if an integer, num1, is evenly divisible by 5 and false otherwise.

num1 % 5 == 0

This is a boolean expression that will evaluate to true if the String, word, is “CS 139” exactly.

word.equals(“CS 139”)

&&, ||, and ! are examples of this.

Logical operators

This line contains a loop decision.

18, 25, 49

This line contains a loop update.

40,42, 29, 49

This is one update statement.

pos++; cont = true (false); letterStr = keyboard.nextLine();

If we had the word, “Jeopardy”, and the letter “z”, how many times would the loop body in countLetter execute.

8 times, once for each letter.

This kind of loop is a post condition loop.

do while

You have a random number generator declared as rand. This statement will generate a number in the range of 13 – 22.

rand.nextInt(10) + 13

This line contains the declaration of a reference type variable.

7, 8, 9, 10, (5), 45

This statement instantiates a reference object.

keyboard = new Scanner(System.in);

This is a primitive literal found in the file.

0, true, false, 1

These are two of the three variables local to the countLetter method.

word, letter, count, pos