Logical and Relational Operation Session 5 Course: T-0974 Algorithm & Object-Oriented Programming I Year: 2010.

Slides:



Advertisements
Similar presentations
Counters and Registers
Advertisements

Looking Inside the Black Box
- 1 - Using an SMT Solver and Craig Interpolation to Detect and Remove Redundant Linear Constraints in Representations of Non-Convex Polyhedra Christoph.
Register Transfer and Microoperations Part2
1 C Programming. 2 Operators 3 Operators in C An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Fast Algorithms for Finding Nearest Common Ancestors Dov Harel and Robert Endre Tarjan Fast Algorithms for Finding Nearest Common Ancestors SIAM J. COMPUT.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
15 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Introduction to Programming Java Lab 5: Boolean Operations 8 February JavaLab5 lecture slides.ppt Ping Brennan
Introduction to Programming
A Simple ALU Binary Logic.
B261 Systems Architecture
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
Truth Tables & Logic Expressions
Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
Digital Systems Introduction Binary Quantities and Variables
Computer Systems – Logic Gates Introduce the basic logic gates Introduce truth tables Introduce Boolean algebra (dont panic!) Examples of combining gates.
Logic Gates & Circuits. AND Gate Input AInput BOutput X AND Logic Gate AND Truth Table X = A. B AND Boolean Expression.
Data Type & Input/Output Session 3 Course: T0974-Algorithm & Object-Oriented Programming I Year: 2010.
Chapter 13 Numerical Issues
CS1022 Computer Programming & Principles
Binary Lesson 3 Hexadecimal. Counting to 15 Base Base Base 16 Base Base Base 16 Two Ten (Hex) Two Ten (Hex)
Binary Lesson 3 Hexadecimal. Counting to 15 Base Base Base 16 Base Base Base 16 Two Ten (Hex) Two Ten (Hex)
Digital Logic & Design Lecture No. 3. Number System Conversion Conversion between binary and octal can be carried out by inspection.  Each octal digit.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Flow of Control Usually the order of statement execution through a method is linear: one after another flow of control: the order statements are executed.
COMP 14 Introduction to Programming
Introduction to Programming G51PRG University of Nottingham Revision 1
SORTING Matakuliah: T0974 / Algoritma dan Metode Object Oriented Programming I Tahun: 2008 Versi: 1/0.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Q1 Review. Other News US News top CS Universities global-universities/computer- science?int=994b08.
Air Force Institute of Technology Electrical and Computer Engineering
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Introduction to Computers and Programming Lecture 7:
24/06/2015CSE1303 Part B lecture notes 1 Words, bits and pieces Lecture B05 Lecture notes section B05.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Primitive Types CSE 115 Spring 2006 April 3 &
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
XOR and XNOR Logic Gates. XOR Function Output Y is TRUE if input A OR input B are TRUE Exclusively, else it is FALSE. Logic Symbol  Description  Truth.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Islamic University Of Gaza, Nael Aburas Data Storage Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Bitwise Operators Fall 2008 Dr. David A. Gaitros
Logical and Relational Operation Session 5 Course: T0974 Algorithm & Object-Oriented Programming I Year: 2011.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Sahar Mosleh California State University San MarcosPage 1 Data Types and Operators.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Programming in java Lecture-3 (a). Java Data Type TypeDescription byte8 bit signed integer short16 but signed integer int32 bit signed integer long64.
Control statements Mostafa Abdallah
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
University of Central Florida COP 3330 Object Oriented Programming
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
University of Central Florida COP 3330 Object Oriented Programming
Lecture 5 from (Chapter 4, pages 73 to 96)
OPERATORS (2) CSC 111.
Starting JavaProgramming
Introduction to Programming
Relational Operators Operator Meaning < Less than > Greater than
Presentation transcript:

Logical and Relational Operation Session 5 Course: T-0974 Algorithm & Object-Oriented Programming I Year: 2010

Bina Nusantara Learning Outcomes After taking this course, student should be expected to apply and demonstrate using Relational and comparator operator, Logical operator and bitwise operator.

Bina Nusantara Lecture outline Relational & Comparator procedure Relational & Comparator operator Logic & Boolean procedure Logic & Boolean operator Truth table Bitwise Operation

Bina Nusantara Relational procedure Relational procedure == Comparator procedure. Comparing two values. Using 6 relational/comparator operator. The result has Boolean type. The values have number, ASCII, or String data type.

Bina Nusantara Comparator operator OperatorDescriptionExampleResult <less than1 < 2true <=less than or equal to1 <= 2true >greater than1 > 2false >=greater than or equal to1 >= 2false ==equal to1 == 2false !=not equal to1 != 2true

Bina Nusantara Comparator operator Character can be compared by refering to its ASCII number. –Example: ‘a’ is more bigger than ‘A’ because ASCII number for ‘a’ (97) is bigger than ASCII number for ‘A’ (65). Word can be compared by String helper. Comparator operator is different than asssignment operator. X = 14  store 14 to X. X == 14  compare if X is equal to 14.

Bina Nusantara Comparator Operation

Bina Nusantara Logic/Boolean Procedure Logical procedure == Boolean procedure. Execute 1 or 2 logic values. It has 4 types Logic/Boolean operator. The result has Boolean data type. Truth table

Bina Nusantara Boolean Operator OperatorNameDescription !notlogical negation &&andlogical conjunction ||orlogical disjunction ^exclusive orlogical exclusion

Bina Nusantara NOT (!) p!pExample truefalse!(1>2) is true, because (1>2) is false falsetrue!(1>0) is false, because (1>0) is true Operator not (!) inverts the original value. true  false and false  true

Bina Nusantara AND (&&) p1p2p1 && p2Example false (2>3) && (5>5) is false Because both (2>3) and (5>5) are false falsetruefalse(2>3) && (6>5) is false Because (2>3) is false truefalse (6>5) && (2>3) is false Because (2>3) is false true (3>2) && (5>=5) is true Because both (3>2) and (5>=5) are true AND Operator (&&) is true when all of its operands are true. If one of its operand is false, then AND is false.

Bina Nusantara OR (||) p1p2p1 || p2Example false (2>3) || (5>5) is false Because both (2>3) and (5>5) are false falsetrue (2>3) || (6>5) is true Because (6>5) is true truefalsetrue(6>5) || (2>3) is true Because (6>5) is true true (3>2) || (5>=5) is true Because both (3>2) and (5>=5) are true OR (||) Operator is true if one of every its operand is true. If all of its operands become false then OR is false.

Bina Nusantara XOR (^) p1p2p1 ^ p2Example false (2>3) ^ (5>5) is false Because both (2>3) and (5>5) are false falsetrue (2>3) ^ (6>5) is true Because (2>3) is false and (6>5) is true truefalsetrue(6>5) ^ (2>3) is true Because (6>5) is true and (2>3) is false true false(3>2) ^ (5>=5) is true Because both (3>2) and (5>=5) are true Operator XOR (^) is true when both if its operands has different condition. When its operands has same condition then XOR is false.

Bina Nusantara Tabel Kebenaran: Demo

Bina Nusantara Thruth Table: Demo

Bina Nusantara Thruth table: Leap Year

Bina Nusantara Did You Know? When evaluating p1&&p2, Java evaluates p1 first. –If p1 is true then Java evaluates p2. –If p2 is false then Java doesn’t evaluate p2. When evaluating p1||p2, Java evaluates p1 first –If p1 is true then Java doesn’t evaluate p2. –If p1 is false then Java evaluates p2.

Bina Nusantara Advanced Learning Bit : the smallest unit in data. 1 byte = 8 bits. 1 bit has 0 or 1. Java support bitwise operator to do bit shift. Example :           255

Bina Nusantara Advanced Learning Bit’s values is same as boolean –1 : true –0 : false Its procedure is same as logical procedure. &  && (AND) |  || (OR) ^  ^ (XOR) ~  ! (NOT/NEGATE) Additional operator << : shift left (unsigned) >> : shift right (signed) >>> : shift right (unsigned)

Bina Nusantara Advanced Learning OperatorNamaExampleDeskripsi &AND & Result: If both of its bits is 1 then it produces 1. |OR | Result: If one of its bits is 1 then it produces 1. ^XOR ^ Hasil: If both of its bits have different values then it produces 1. ~NEGATE~ Hasil: If bit = 1  0 If bit = 0  1 <<LEFT SHIFT << 2 Hasil: Shift 2 bit to the left then fill the latter with zeros. >>RIGHT SHIFT (SIGNED) >> 2 Hasil: >> 2 Hasil: Shift 2 bit to the right then fill the latter with zeros. Its Least Significant Bit is sign bit. >>>RIGHT SHIFT (UNSIGNED) >>> 2 Hasil: Shift 2 bit to the right then fill the latter with zeros.

Bina Nusantara Advanced Learning Shorthand for bitwise operation : &=, |=, ^=, >=, >>>= Bitwise only can be used for real number like : byte, short, int and long. Bitwise for Char type converts to int which refer to ASCII number.

Bina Nusantara Advanced Learning

Bina Nusantara Advanced Learning

Latihan Buatlah program menerima input Nama, Total belanja Jika belanja >100rb, maka disc 10% selain itu tidak ada discount. (gunakan kelas Scanner) Bina Nusantara University 25

import java.util.*; class Belanja { public static void main(String args[]) { String nama; boolean member=true; double belanja=0.0; Scanner in =new Scanner(System.in) System.out.println("Masukkan Nama"); nama=in.nextLine(); System.out.println("Masukkan Belanja"); belanja=in.nextInt(); Bina Nusantara University 26 if ((belanja >100000|| member==true) && belanja <500000) { belanja =belanja -(belanja*0.1); System.out.println ("Total belanja"+ belanja); } elseif (belanja >=500000) { belanja =belanja -(belanja*0.2); System.out.println ("Total belanja"+ belanja); } else { System.out.println ("Total belanja"+ belanja); }

Bina Nusantara References Introduction to Java Programming. 6ed. Liang p94-98, p1279 Dasar Pemrograman Java 2. Abdul Kadir p76-83 The Complete Reference Java. 5ed. Herbert Schildt p62-76 Java 2 Weekend Crash Course. Julio Sanchez p85-96 Bitwise: – – – –