Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.

Slides:



Advertisements
Similar presentations
Escape Sequences \n newline \t tab \b backspace \r carriage return
Advertisements

Arithmetic Calculations
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Return values.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
1 Chapter 3 Arithmetic Expressions. 2 Chapter 3 Topics l Overview of Java Data Types l Numeric Data Types l Declarations for Numeric Expressions l Simple.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
ICS 103 Lab 2-Arithmetic Expressions. Lab Objectives Learn different arithmetic operators Learn different arithmetic operators Learn how to use arithmetic.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
ISBN Chapter 7 Expressions and Assignment Statements.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
What is a variable?  A variable holds data in memory so the program may use that data, or store results.  Variables have a data type. int, boolean, char,
7-1 Chapter 7: Expressions and Assignment Statements Arithmetic Expressions –the fundamental means of specifying computations in a programming language.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
C H A P T E R S E V E N Expressions and Assignment Statements.
1 Number Types  Every value in Java is either: 1.a reference to an object or 2.one of the eight primitive types  eight primitive types: a.four integer.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
C Operators. CONTENTS CONDITIONAL OPERATOR SIMPLE ASSIGNMENT OPERATOR COMPOUND ASSIGNMENT OPERATOR BITWISE OPERATOR OPERATOR PRECEDENCE.
Java Software Solutions Lewis and Loftus Chapter 5 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. More Programming Constructs.
Universidad Nacional de Colombia Facultad de Ingeniería Departamento de Sistemas ertificación en AVA.
Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY.
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. int: integers, no fractional part: 1, -4, 0 double : floating-point.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
CPS120: Introduction to Computer Science Operations Lecture 9.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
ISBN Chapter 7 Expressions and Assignment Statements.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 Lecture 5 More Programming Constructs Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
JAVA Practical Unary operators 2. Using Reals 3. Conversions 4. Type Casting 5. Scope 6. Constants.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Expressions and Assignment Statements
Expressions and Assignment Statements
Chapter 7: Expressions and Assignment Statements
Operators and Expressions
Expressions and Assignment Statements
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Chapter 7: Expressions and Assignment Statements
Assignment and Arithmetic expressions
Intro to C Tutorial 4: Arithmetic and Logical expressions
Expressions and Assignment Statements
Operators and Expressions
Lecture 3 Expressions Richard Gesick.
All the Operators 22-Nov-18.
Expressions and Assignment Statements
All the Operators 4-Dec-18.
Chapter-3 Operators.
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Chap 7. Advanced Control Statements in Java
OPERATORS in C Programming
OPERATORS in C Programming
Presentation transcript:

Pemrograman Dasar - Data Types1 OPERATOR

Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both arguments are integer and floating-point otherwise.  Modulo operator is denoted by % ( mod )  Example 15 / 2 = 7 15 % 2 = 1 15,0 / 2 = 7,5  Integer division by 0 raises exception  Floating-point division by 0 yields infinite or NaN (Not a number)  X += 4; is equivalent to x = x+4;

Pemrograman Dasar - Data Types3 Increment and Decrement Operator  x++, x--, ++x, --x  Be careful with the prefix and postfix form. int m = 7; Int n = 7; Int a = 2 * ++m; // now a is 16, m is 8 int b = 2 * n++; // now b is 14, n is 8  x++ is called increment operator (x=x+1)  x-- is called decrement operator (x=x-1)

Pemrograman Dasar - Data Types4 Relational and boolean operator  To test equality, Java uses double equal signs, ==, for example 3==7 is false  Inequality is denoted by != sign, for example 3 !=7 is true  < is for less than  > is for greater than  <= is less than or equal  >= is greater than or equal  && is for ‘and’  || is for ’or’  ! is negation operator  Java supports ternary operator ‘?’. The expression condition ? ex1 : ex2 evaluates to ex1 if the condition is true, to ex2 if the condition is false. E.g. x < y ? x : y gives the smaller number of x and y.

Pemrograman Dasar - Data Types5 Bitwise Operator  & (and), | (or), ^ (xor), ~ (not)  These operators work on bit patterns.  E.g int n = 17; Int fourthBitFromRight = (n & 8)/ 8;  gives a one if the fourth bit from right in the binary representation of n is one, and a zero if not.

Pemrograman Dasar - Data Types6 Mathematical Function and Constant  Math class provides mathematical function and constants  Math.sqrt(); Math.pow(x,a); // x a double x = 4; double y = Math.sqrt(x); System.out.println(y);  Notes There is a difference betweem sqrt() method and println() method. The println() method operates on an object System.out and has second parameter ‘y’ to be printed. But the sqrt() method in the Math class does not operates on any object. It has single parameter x. Such method is called as static method

Pemrograman Dasar - Data Types7 Mathematical funcstion and constant (cont)  Math class suplies also trigonometric functions Math.sin Math.cos Math.tan Math.atan  Eponential and log Math.exp Math.log  Two constants Math.PI Math.E

Pemrograman Dasar - Data Types8 Cast  Convert a type o variable to another type  The syntax for casting is to give the target type in parentheses,followed by the variable name.  E.g. double x = 9,997; int y = (int)x; So, the variable y hasthe value 9, as casting a floating-point value to an integer discards the fractional part.

Pemrograman Dasar - Data Types9