Computational Expression

Similar documents
Flow of Control. Flow of control The order in which statements are executed. Transfer of control

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Introduction to Bioinformatics

BIL101E: Introduction to Computers and Information systems Lecture 8

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Information Science 1

LECTURE 5 Control Structures Part 2

CS 199 Computer Programming. Spring 2018 Lecture 5 Control Statements

JAVA OPERATORS GENERAL

Theory of control structures

Information Science 1

Eng. Mohammed S. Abdualal

Lecture 5 Tao Wang 1

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

MEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1. March 28-30, 2007

IEEE Floating-Point Representation 1

++x vs. x++ We will use these notations very often.

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Computational Expression

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Advanced if/else & Cumulative Sum

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

1 class Lecture3 { 2 3 "Selections" // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 88 / 133

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures in Java if-else and switch

Chapter 3. Selections

Introduction to Programming

CONDITIONAL EXECUTION

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

Logic is the anatomy of thought. John Locke ( ) This sentence is false.

Structured Program Development

Computational Expression

1 class Lecture3 { 2 3 "Selections" // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 89 / 137

Chapter Goals. 3.1 The if Statement. Contents 1/30/2013 DECISIONS

Microsoft Visual Basic 2005: Reloaded

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

CT 229 Java Syntax Continued

Arithmetic Compound Assignment Operators

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Scanner Objects. Zheng-Liang Lu Java Programming 82 / 133

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements

Selenium Class 9 - Java Operators

Decision Making in C

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

Control Structures in Java if-else and switch

Flow Control. So Far: Writing simple statements that get executed one after another.

Programming Language Concepts Control Flow. Janyl Jumadinova 2 February, 2017

APCS Semester #1 Final Exam Practice Problems

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Lecture 4: Conditionals

Conditional Programming

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

STUDENT LESSON A12 Iterations

Fundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

STUDENT LESSON A14 Boolean Algebra and Loop Boundaries

Introduction to Computer Science I

Introduction to Computer Science I

Prof. Navrati Saxena TA: Rochak Sachan

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

Computer Science & Engineering 150A Problem Solving Using Computers

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Lab 8: IF statement. Conditionals and Loops. Copyright 2012 Pearson Education, Inc.

Conditional Statement

Conditions, logical expressions, and selection. Introduction to control structures

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Selections. CSE 114, Computer Science 1 Stony Brook University

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

5. Selection: If and Switch Controls

Introduction to C Programming

Decisions (If Statements) And Boolean Expressions

CS 106 Introduction to Computer Science I

Java Simple Data Types

Computational Expression

In this chapter, you will:

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Object Oriented Programming with Java

CS125 : Introduction to Computer Science. Lecture Notes #6 Compound Statements, Scope, and Advanced Conditionals

Java Programming for Selenium

Lecture 5: Making Decisions

Program Development. Chapter 3: Program Statements. Program Statements. Requirements. Java Software Solutions for AP* Computer Science A 2nd Edition

Chapter 3: Program Statements

Chapter 4: Making Decisions

Computers and FORTRAN Language Fortran 95/2003. Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes. Topics:

M275 - Web Development using PHP and MySQL

Place your name tag here

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

Chapter 4: Making Decisions

Chapter 4. Flow of Control

C++ Programming: From Problem Analysis to Program Design, Third Edition

Introduction to Computer Science I

Transcription:

Computational Expression Conditionals Janyl Jumadinova 10 October, 2018 Janyl Jumadinova Computational Expression 10 October, 2018 1 / 16

Computational Thinking: a problem solving process Decomposition Pattern Recognition Abstraction Algorithm Design Janyl Jumadinova Computational Expression 10 October, 2018 2 / 16

Algorithms Algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. Janyl Jumadinova Computational Expression 10 October, 2018 3 / 16

Algorithms Algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. Janyl Jumadinova Computational Expression 10 October, 2018 3 / 16

Control Structures We may need to be able to make decisions (selection) and repeat actions (looping) in our programs to allow for more complex programs. Selection and looping are common to all programming languages. The way they implement these concepts, however, may differ from language to language. Janyl Jumadinova Computational Expression 10 October, 2018 4 / 16

Control Structures Three Groups of Control Structures 1 Sequential Structure - It is just built into the language itself. Janyl Jumadinova Computational Expression 10 October, 2018 5 / 16

Control Structures Three Groups of Control Structures 1 Sequential Structure 2 Selection Structures - if : single selection - if/else : double or multiple selection - switch : multiple selection Janyl Jumadinova Computational Expression 10 October, 2018 6 / 16

Control Structures Three Groups of Control Structures 1 Sequential Structure 2 Selection Structures 3 Repetition Structure while do/while for Janyl Jumadinova Computational Expression 10 October, 2018 7 / 16

Control Structures Java programs are built from only these seven control structures: three selection (if, if/else, switch) three repetition (while, do/while, for) You implement computer algorithms by stringing sequences of these seven control structures together. Janyl Jumadinova Computational Expression 10 October, 2018 8 / 16

if/else if only has a do it or don t do it mentality if the assertion is true, you do the associated action, if it s false, you skip it. Janyl Jumadinova Computational Expression 10 October, 2018 9 / 16

if/else if only has a do it or don t do it mentality if the assertion is true, you do the associated action, if it s false, you skip it. The if/else structure gives more flexibility by providing something to do if the assertion is false the else portion of the structure. Nested if/else structure strings together multiple if/else statements to handle a range of values. Janyl Jumadinova Computational Expression 10 October, 2018 9 / 16

Which of these code segments will determine a letter grade correctly based on a variable grade? if (grade < 60) if (grade >= 90) System.out.println("F"); System.out.println("A"); else if (grade >= 60) else if (grade >= 80) System.out.println("D"); System.out.println("B"); else if (grade >= 70) else if (grade >= 70) System.out.println("C"); System.out.println("C"); else if (grade >= 80) else if (grade >= 60) System.out.println("D"); System.out.println("D"); else else System.out.println("A"); System.out.println("F"); Janyl Jumadinova Computational Expression 10 October, 2018 10 / 16

Compound Statements What if you wanted to do more than one thing in an if or an if/else action? Need to use braces ({ and }) to form a compound statement. Janyl Jumadinova Computational Expression 10 October, 2018 11 / 16

if and if/else tips to remember: They can be used to test ranges of values. In a nested if/else structure, an else always attempts to match up with the closest and most immediately unmatched preceding if statement. Always use compound statements with if/else structures to prevent problems down the road. Janyl Jumadinova Computational Expression 10 October, 2018 12 / 16

Logical Operators Using logical operators, we have a way to string multiple simple conditions together to help avoid/simplify nesting statements. These logical operators are based on the concept of Boolean logic or Boolean algebra. Janyl Jumadinova Computational Expression 10 October, 2018 13 / 16

Logical Operators Using logical operators, we have a way to string multiple simple conditions together to help avoid/simplify nesting statements. These logical operators are based on the concept of Boolean logic or Boolean algebra. These are the three logical operators in Java: 1 && (logical AND) 2 (logical OR) 3! (logical NOT, or negation) Janyl Jumadinova Computational Expression 10 October, 2018 13 / 16

Logical and Truth Table Janyl Jumadinova Computational Expression 10 October, 2018 14 / 16

Logical or Truth Table Janyl Jumadinova Computational Expression 10 October, 2018 15 / 16

Logical not Truth Table Janyl Jumadinova Computational Expression 10 October, 2018 16 / 16