SlideShare a Scribd company logo
1 of 13
- Ankita Karia




Ankita R Karia   1 February 2012   1
   JAVA operators can be classified into a number of related
    categories as below:-
      Arithmetic.            + - * / %


      Relational.         < <= > >= == !=
                              &&              ||                      !
      Logical.              AND              OR                     NOT

                         T && T = T F || F= F                       T=F
                                                                    F=T
                                        Ankita R Karia   1 February 2012   2
ASSIGNMENT         CONDITIONAL                         INCREMENT
         =                 ? :                                ++
• Is used to      exp1 ? exp2 : exp3                   •PRE:- First
assign value to   e.g.:- x=(a>b)?a:b                   subtracts 1 from
                                                       operand and then the
variable.                                              result is assigned .
e.g.:- a =10        DECREMENT - -                             ++m;
•SHORTHAND
     a=a+1        • PRE:- First subtracts 1            •POST:- First
                                                       assigns the value to
Can also be       from operand and then the
                                                       the variable on left and
                  result is assigned .
written as            - - m;                           then decrements
      a+=1                                             operand
                  •POST:- First assigns the
                                                               m++
a = a / (n+1)     value to the variable on left
                  and then decrements
                  operand
                      m--                   Ankita R Karia   1 February 2012   3
   JAVA permits mixing of constants and variables of different
    types in an expression, but during evaluation it adheres to
    very strict rules of type conversion.
   If operands are of different types, the “lower” type is
    automatically converted to “higher” type before the operation
    proceeds. The result is of higher type.
   The final result of an expression is converted to the type of
    the variable on the left of the assignment before assigning the
    value

                                              Ankita R Karia   1 February 2012   4
EXAMPLES                       ACTION
x= (int) 7.5             7.5 is converted to integer by
                         truncation
a = (int)21.3/(int)4.5   Evaluated as 21/4 and the result
                         would be 5
b = (double) sum/n       Division is done in floating point
                         mode
y = (int) (a+b)          The result of a+b is converted to
                         integer
y = (int) a+b            a is converted to integer and then
                         added to b

p = cost ((double)x)     Converts x to double before using
                         it as parameter
                                  Ankita R Karia   1 February 2012   5
   JAVA supports basic math functions through Math class
    defined in the java.lang.package.
   The functions should be used as follows:-

            Math.function_name();
                         java.lang.Math
 Example: y = Math.sqrt(x);



                                        Function
                                         name
                                           Ankita R Karia   1 February 2012   6
FUNCTIONS                        ACTION
   sin(x)      Returns the sine of the angle x in radians
  cos(x)      Returns the cosine of the angle x in radians
   tan(x)     Returns the tangent of the angle x in radians
  asin(x)          Returns the angle whose sine is y
 atan2(x,y)     Returns the angle whose tangent is x/y
 pow(x,y)                        Returns xy
  exp(x)                         Returns ex
   log(x)          Returns the natural logarithm of x
  sqrt(x)               Returns square root of x
  abs(x)                  Returns absolute of x
 max(a,b)            Returns maximum of1 a and b
                                Ankita R Karia February 2012   7
 Determine   the value of the following
 arithmetic expression. (a=5,b=2,c=1)
1. m = ++a*5;

2. p*=x/y; x=10,y=2,p=2;

3. s/=5;   s=5;
4. n=b++-c*2;

                               Ankita R Karia   1 February 2012   8
Ankita R Karia   1 February 2012   9
Ankita R Karia   1 February 2012   10
   Determine the value of the following logical
    expression. (a=5,b=10,c=-6)
1. a<b && a<c;

2. a<b && a>c;

3. a= = c || b>a;

4. b>15 && c<0 || a>0;

5. (a/2.0==0.0&&b/2.0!=0.0)||c<0.0

                                  Ankita R Karia   1 February 2012   11
Ankita R Karia   1 February 2012   12
1. The straight-line method of computing the yearly depreciation of the value of an item
   is given by
                depreciation = Purchase Price – Salvage Value
                                     Years of service
  Write a program to determine the salvage value of an item when the purchase price,
                  years of service and Annual depreciation are given

                                                        Ankita R Karia   1 February 2012   13

More Related Content

What's hot

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 

What's hot (20)

9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 

Viewers also liked

Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
vishaljot_kaur
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
Jin Castor
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
Ravi_Kant_Sahu
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
harshaltambe
 

Viewers also liked (20)

Operators in java
Operators in javaOperators in java
Operators in java
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
 
Control structures i
Control structures i Control structures i
Control structures i
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in javaData types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in java
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 
Java 2
Java 2Java 2
Java 2
 
Təhlükəsiz proqram təminatının java mühitində hazırlanma texnologiyaları
Təhlükəsiz proqram təminatının java mühitində hazırlanma texnologiyalarıTəhlükəsiz proqram təminatının java mühitində hazırlanma texnologiyaları
Təhlükəsiz proqram təminatının java mühitində hazırlanma texnologiyaları
 
Fişinqdən necə qorunmaq olar?
Fişinqdən necə qorunmaq olar?Fişinqdən necə qorunmaq olar?
Fişinqdən necə qorunmaq olar?
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Java proqramlaşdirma mühitində təhlükəsiz proqram təminatinin hazirlanma texn...
Java proqramlaşdirma mühitində təhlükəsiz proqram təminatinin hazirlanma texn...Java proqramlaşdirma mühitində təhlükəsiz proqram təminatinin hazirlanma texn...
Java proqramlaşdirma mühitində təhlükəsiz proqram təminatinin hazirlanma texn...
 
Jdbc
JdbcJdbc
Jdbc
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Basic JSTL
Basic JSTLBasic JSTL
Basic JSTL
 
15 bitwise operators
15 bitwise operators15 bitwise operators
15 bitwise operators
 
jstl ( jsp standard tag library )
jstl ( jsp standard tag library )jstl ( jsp standard tag library )
jstl ( jsp standard tag library )
 

Similar to Operators and Expressions in Java

Similar to Operators and Expressions in Java (20)

MATH-412-TUMANDAY Report in Mat-Math.pptx
MATH-412-TUMANDAY Report in Mat-Math.pptxMATH-412-TUMANDAY Report in Mat-Math.pptx
MATH-412-TUMANDAY Report in Mat-Math.pptx
 
Chpt 2-functions-seqs v.5
Chpt 2-functions-seqs v.5Chpt 2-functions-seqs v.5
Chpt 2-functions-seqs v.5
 
Module Seven Lesson Four Remediation Notes
Module Seven Lesson Four Remediation NotesModule Seven Lesson Four Remediation Notes
Module Seven Lesson Four Remediation Notes
 
power point presentation on genmath_lesson1_2_.pptx
power point presentation on genmath_lesson1_2_.pptxpower point presentation on genmath_lesson1_2_.pptx
power point presentation on genmath_lesson1_2_.pptx
 
C language basics
C language basicsC language basics
C language basics
 
Relations and Functions #BB2.0.pdf
Relations and Functions #BB2.0.pdfRelations and Functions #BB2.0.pdf
Relations and Functions #BB2.0.pdf
 
Inverse function
Inverse function Inverse function
Inverse function
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
Functions
FunctionsFunctions
Functions
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 
2.4 Linear Functions
2.4 Linear Functions2.4 Linear Functions
2.4 Linear Functions
 
Unit 4
Unit 4Unit 4
Unit 4
 
Tema 1 funciones
Tema 1 funcionesTema 1 funciones
Tema 1 funciones
 
Paper no. 4
Paper no. 4Paper no. 4
Paper no. 4
 
Paper no. 4
Paper no. 4Paper no. 4
Paper no. 4
 
Indefinite Integration One shot Revision
Indefinite Integration One shot Revision Indefinite Integration One shot Revision
Indefinite Integration One shot Revision
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
 
BP106RMT.pdf
BP106RMT.pdfBP106RMT.pdf
BP106RMT.pdf
 

More from Abhilash Nair (20)

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
 
MSI Shift Registers
MSI Shift RegistersMSI Shift Registers
MSI Shift Registers
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
 
VHDL - Part 2
VHDL - Part 2VHDL - Part 2
VHDL - Part 2
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
 
Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
 
FPGA
FPGAFPGA
FPGA
 
FPLDs
FPLDsFPLDs
FPLDs
 
CPLDs
CPLDsCPLDs
CPLDs
 
CPLD & FPLD
CPLD & FPLDCPLD & FPLD
CPLD & FPLD
 
CPLDs
CPLDsCPLDs
CPLDs
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Operators and Expressions in Java

  • 1. - Ankita Karia Ankita R Karia 1 February 2012 1
  • 2. JAVA operators can be classified into a number of related categories as below:-  Arithmetic. + - * / %  Relational. < <= > >= == != && || !  Logical. AND OR NOT T && T = T F || F= F T=F F=T Ankita R Karia 1 February 2012 2
  • 3. ASSIGNMENT CONDITIONAL INCREMENT = ? : ++ • Is used to exp1 ? exp2 : exp3 •PRE:- First assign value to e.g.:- x=(a>b)?a:b subtracts 1 from operand and then the variable. result is assigned . e.g.:- a =10 DECREMENT - - ++m; •SHORTHAND a=a+1 • PRE:- First subtracts 1 •POST:- First assigns the value to Can also be from operand and then the the variable on left and result is assigned . written as - - m; then decrements a+=1 operand •POST:- First assigns the m++ a = a / (n+1) value to the variable on left and then decrements operand m-- Ankita R Karia 1 February 2012 3
  • 4. JAVA permits mixing of constants and variables of different types in an expression, but during evaluation it adheres to very strict rules of type conversion.  If operands are of different types, the “lower” type is automatically converted to “higher” type before the operation proceeds. The result is of higher type.  The final result of an expression is converted to the type of the variable on the left of the assignment before assigning the value Ankita R Karia 1 February 2012 4
  • 5. EXAMPLES ACTION x= (int) 7.5 7.5 is converted to integer by truncation a = (int)21.3/(int)4.5 Evaluated as 21/4 and the result would be 5 b = (double) sum/n Division is done in floating point mode y = (int) (a+b) The result of a+b is converted to integer y = (int) a+b a is converted to integer and then added to b p = cost ((double)x) Converts x to double before using it as parameter Ankita R Karia 1 February 2012 5
  • 6. JAVA supports basic math functions through Math class defined in the java.lang.package.  The functions should be used as follows:- Math.function_name(); java.lang.Math  Example: y = Math.sqrt(x); Function name Ankita R Karia 1 February 2012 6
  • 7. FUNCTIONS ACTION sin(x) Returns the sine of the angle x in radians cos(x) Returns the cosine of the angle x in radians tan(x) Returns the tangent of the angle x in radians asin(x) Returns the angle whose sine is y atan2(x,y) Returns the angle whose tangent is x/y pow(x,y) Returns xy exp(x) Returns ex log(x) Returns the natural logarithm of x sqrt(x) Returns square root of x abs(x) Returns absolute of x max(a,b) Returns maximum of1 a and b Ankita R Karia February 2012 7
  • 8.  Determine the value of the following arithmetic expression. (a=5,b=2,c=1) 1. m = ++a*5; 2. p*=x/y; x=10,y=2,p=2; 3. s/=5; s=5; 4. n=b++-c*2; Ankita R Karia 1 February 2012 8
  • 9. Ankita R Karia 1 February 2012 9
  • 10. Ankita R Karia 1 February 2012 10
  • 11. Determine the value of the following logical expression. (a=5,b=10,c=-6) 1. a<b && a<c; 2. a<b && a>c; 3. a= = c || b>a; 4. b>15 && c<0 || a>0; 5. (a/2.0==0.0&&b/2.0!=0.0)||c<0.0 Ankita R Karia 1 February 2012 11
  • 12. Ankita R Karia 1 February 2012 12
  • 13. 1. The straight-line method of computing the yearly depreciation of the value of an item is given by depreciation = Purchase Price – Salvage Value Years of service Write a program to determine the salvage value of an item when the purchase price, years of service and Annual depreciation are given Ankita R Karia 1 February 2012 13