SlideShare a Scribd company logo
By :
Java Operators
The operators in Java are like the following :
1.  Arithme*c	
  operators	
  .	
  
2.  Rela*onal	
  operators.	
  
3.  Logical	
  operators.	
  
4.  Assignment	
  operators.	
  
Arithmetic Operators
Operator	
   Descrip-on	
   Example	
  
+	
   Addi-on	
  –	
  Adds	
  values	
  on	
  either	
  side	
  of	
  the	
  operator	
   A + B will give 30 
-­‐	
   Subtrac-on	
  –	
  Subtracts	
  right	
  hand	
  from	
  le?	
  hand	
  	
   A - B will give -10 
*	
   Mul-plica-on	
  -­‐	
  Mul-plies	
  values	
  on	
  either	
  side	
  of	
  the	
  operator	
  	
   A * B will give 200 
/	
   Division	
  -­‐	
  Divides	
  le?	
  hand	
  operand	
  by	
  right	
  hand	
  operand	
  	
   B / A will give 2 
%	
  
Modulus	
  -­‐	
  Divides	
  le?	
  hand	
  operand	
  by	
  right	
  hand	
  operand	
  and	
  
returns	
  remainder	
  	
  
B % A will give 0 
++	
   Increment	
  -­‐	
  Increases	
  the	
  value	
  of	
  operand	
  by	
  1	
  	
   B++ gives 21 
-­‐-­‐	
   Decrement	
  -­‐	
  Decreases	
  the	
  value	
  of	
  operand	
  by	
  1	
  	
   B-- gives 19 
Arithmetic operators are used in mathematical expressions in the same way that they
are used in algebra.
The following table lists the arithmetic operators:
Assume integer variable A holds 10 and variable B holds 20, then:
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( A + B ) ;
}
010101010101010101010101	
  
30	
  
Addition Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( A - B ) ;
}
010101010101010101010101	
  
-10	
  
Subtraction Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( A * B ) ;
}
010101010101010101010101	
  
200	
  
Multiplication Operators
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( B / A ) ;
}
010101010101010101010101	
  
2	
  
Divition Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( B % A ) ;
}
010101010101010101010101	
  
0	
  
Modulus Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( + + B ) ;
}
010101010101010101010101	
  
Increment Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( + + B ) ;
}
010101010101010101010101	
  
Increment Operator
A=10 B=21
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( + + B ) ;
}
010101010101010101010101	
  
Increment Operator
A=10 B=21
21	
  
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println (B + +) ;
}
010101010101010101010101	
  
20	
  
Increment Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println (B + +) ;
}
010101010101010101010101	
  
20	
  
Increment Operator
A=10 B=21
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( - - B) ;
}
010101010101010101010101	
  
Decrement Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( - - B) ;
}
010101010101010101010101	
  
Decrement Operator
A=10 B=19
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( - - B) ;
}
010101010101010101010101	
  
Decrement Operator
A=10 B=19
19	
  
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( B - - ) ;
}
010101010101010101010101	
  
Decrement Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( B - - ) ;
}
010101010101010101010101	
  
20	
  
Decrement Operator
A=10 B=20
public static void main(String[] args) {
int A , B ;
A=10 ;
B=20 ;
System.out.println ( B - - ) ;
}
010101010101010101010101	
  
20	
  
Decrement Operator
A=10 B=19
Relational Operators
operator	
   Descrip-on	
   Example	
  
==	
  
Checks	
  if	
  the	
  values	
  of	
  two	
  operands	
  are	
  equal	
  or	
  not,	
  if	
  yes	
  then	
  
condi-on	
  becomes	
  true.	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (equal	
  )	
  
(A	
  ==	
  B)	
  is	
  not	
  true.	
  	
  
!=	
  
Checks	
  if	
  the	
  values	
  of	
  two	
  operands	
  are	
  equal	
  or	
  not,	
  if	
  values	
  are	
  not	
  
equal	
  then	
  condi-on	
  becomes	
  true.	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (	
  not	
  equal	
  )	
  
(A	
  !=	
  B)	
  is	
  true.	
  	
  
>	
  
Checks	
  if	
  the	
  value	
  of	
  le?	
  operand	
  is	
  greater	
  than	
  the	
  value	
  of	
  right	
  
operand,	
  if	
  yes	
  then	
  condi-on	
  becomes	
  true.	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (	
  greater	
  than)	
  
(A	
  >	
  B)	
  is	
  not	
  true.	
  	
  
<	
  
Checks	
  if	
  the	
  value	
  of	
  le?	
  operand	
  is	
  less	
  than	
  the	
  value	
  of	
  right	
  operand,	
  
if	
  yes	
  then	
  condi-on	
  becomes	
  true.	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (	
  Less	
  than)	
  
(A	
  <	
  B)	
  is	
  true.	
  	
  
>=	
  
Checks	
  if	
  the	
  value	
  of	
  le?	
  operand	
  is	
  greater	
  than	
  or	
  equal	
  to	
  the	
  value	
  of	
  
right	
  operand,	
  if	
  yes	
  then	
  condi-on	
  becomes	
  true.	
  	
  
(A	
  >=	
  B)	
  is	
  not	
  true.	
  	
  
<=	
  
Checks	
  if	
  the	
  value	
  of	
  le?	
  operand	
  is	
  less	
  than	
  or	
  equal	
  to	
  the	
  value	
  of	
  
right	
  operand,	
  if	
  yes	
  then	
  condi-on	
  becomes	
  true.	
  	
  
(A	
  <=	
  B)	
  is	
  true.	
  	
  
There are following relational operators supported by Java language:
Assume variable A holds 10 and variable B holds 20 , then:
public static void main(String[] args) {
int x , y ;
x = 10 ;
y = 20 ;
System.out.println ( x = = y ) ;
}
010101010101010101010101	
  
False	
  
Relational Operators
x = 10 y = 20
public static void main(String[] args) {
int x , y ;
x = 10 ;
y = 20 ;
System.out.println ( x ! = y ) ;
}
010101010101010101010101	
  
True	
  
Relational Operators
x = 10 y = 20
public static void main(String[] args) {
int x , y ;
x = 10 ;
y = 20 ;
System.out.println ( x > y ) ;
}
010101010101010101010101	
  
False	
  
Relational Operators
x = 10 y = 20
public static void main(String[] args) {
int x , y ;
x = 10 ;
y = 20 ;
System.out.println ( x < y ) ;
}
010101010101010101010101	
  
True	
  
Relational Operators
x = 10 y = 20
public static void main(String[] args) {
int x , y ;
x = 10 ;
y = 20 ;
System.out.println ( x > = y ) ;
}
010101010101010101010101	
  
False	
  
Relational Operators
x = 10 y = 20
public static void main(String[] args) {
int x , y ;
x = 10 ;
y = 20 ;
System.out.println ( x < = y ) ;
}
010101010101010101010101	
  
True	
  
Relational Operators
x = 10 y = 20
Logical Operators
Operator	
   Descrip-on	
   Example	
  
&&	
  
Called	
  Logical	
  AND	
  operator.	
  If	
  both	
  the	
  operands	
  
are	
  non-­‐zero,	
  then	
  the	
  condi-on	
  becomes	
  true.	
  	
  
(A	
  &&	
  B)	
  is	
  false.	
  	
  
||	
  
Called	
   Logical	
   OR	
   Operator.	
   If	
   any	
   of	
   the	
   two	
  
operands	
  are	
  non-­‐zero,	
  then	
  the	
  condi-on	
  becomes	
  
true.	
  	
  
(A	
  ||	
  B)	
  is	
  true.	
  	
  
!	
  
Called	
   Logical	
   NOT	
   Operator.	
   Use	
   to	
   reverses	
   the	
  
logical	
  state	
  of	
  its	
  operand.	
  If	
  a	
  condi-on	
  is	
  true	
  then	
  
Logical	
  NOT	
  operator	
  will	
  make	
  false.	
  	
  
!(A	
  &&	
  B)	
  is	
  true.	
  	
  
The following table lists the logical operators:
Assume Boolean variables A holds true and variable B holds false , then:
public static void main(String[] args) {
int test = 6 ;
If ( test = = 9 ) {
System.out.println( “ yes ” ) ;
} else {
System.out.println( “ this is else ” ) ;
}
}
010101010101010101010101	
  
this is else 	
  
If Statement
test = 6
public static void main(String[] args) {
int boy , girl ;
boy = 18 ;
girl = 68 ;
If ( boy > 10 ) {
System.out.println(“you can enter”) ;
}else{
System.out.println(“you are too young”)
}
}
010101010101010101010101	
  
You can enter	
  
Logical Operators
boy = 18 girl = 68
public static void main(String[] args) {
int boy , girl ;
boy = 18 ;
girl = 68 ;
If ( boy > 10 && girl < 60 ) {
System.out.println(“you can enter”) ;
}else{
System.out.println(“you are too young”);
}
}
010101010101010101010101	
  
You are too young	
  
Logical Operators
boy = 18 girl = 68
public static void main(String[] args) {
int boy , girl ;
boy = 18 ;
girl = 68 ;
If ( boy > 10 | | girl < 60 ) {
System.out.println(“you can enter”) ;
}else{
System.out.println(“you are too young”);
}
}
010101010101010101010101	
  
You can enter	
  
Logical Operators
boy = 18 girl = 68
public static void main(String[] args) {
int boy , girl ;
boy = 18 ;
girl = 68 ;
If (!( boy > 10 && girl < 60 )) {
System.out.println(“you can enter”) ;
}else{
System.out.println(“you are too young”);
}
}
010101010101010101010101	
  
you can enter	
  
Logical Operators
boy = 18 girl = 68
public static void main(String[] args) {
int age ;
age = 3 ;
Switch( age ) {
case1 :
System.out.println(“you can crawl”) ;
break ;
case2 :
System.out.println(“you can talk”) ;
break ;
case3 :
System.out.println(“you can get in trouble”) ;
break ;
default :
System.out.println(“I don’t know how old are you”)
}
010101010101010101010101	
  
you can get in trouble	
  
Logical Operators
age= 3
Assignment Operators
Operator	
   Descrip-on	
   Example	
  
=	
  
Simple	
   assignment	
   operator,	
   Assigns	
   values	
   from	
  
right	
  side	
  operands	
  to	
  le?	
  side	
  operand	
  	
  
C	
  =	
  A	
  +	
  B	
  will	
  assign	
  value	
  of	
  	
  
A	
  +	
  B	
  into	
  C	
  	
  
+=	
  
Add	
  AND	
  assignment	
  operator,	
  It	
  adds	
  right	
  operand	
  
to	
   the	
   le?	
   operand	
   and	
   assign	
   the	
   result	
   to	
   le?	
  
operand	
  
C	
  +=	
  A	
  is	
  equivalent	
  to	
  C	
  =	
  C	
  +	
  A	
  
-­‐=	
  
Subtract	
  AND	
  assignment	
  operator,	
  It	
  subtracts	
  right	
  
operand	
  from	
  the	
  le?	
  operand	
  and	
  assign	
  the	
  result	
  
to	
  le?	
  operand	
  	
  
C	
  -­‐=	
  A	
  is	
  equivalent	
  to	
  C	
  =	
  C	
  -­‐	
  A	
  	
  
*=	
  
Mul-ply	
   AND	
   assignment	
   operator,	
   It	
   mul-plies	
  
right	
  operand	
  with	
  the	
  le?	
  operand	
  and	
  assign	
  the	
  
result	
  to	
  le?	
  operand	
  	
  
C	
  *=	
  A	
  is	
  equivalent	
  to	
  C	
  =	
  C	
  *	
  A	
  	
  
/=	
  
Divide	
   AND	
   assignment	
   operator,	
   It	
   divides	
   le?	
  
operand	
  with	
  the	
  right	
  operand	
  and	
  assign	
  the	
  result	
  
to	
  le?	
  operand	
  	
  
	
  
C	
  /=	
  A	
  is	
  equivalent	
  to	
  C	
  =	
  C	
  /	
  A	
  
%=	
  
Modulus	
   AND	
   assignment	
   operator,	
   It	
   takes	
  
modulus	
  using	
  two	
  operands	
  and	
  assign	
  the	
  result	
  to	
  
le?	
  operand	
  
C	
  %=	
  A	
  is	
  equivalent	
  to	
  C	
  =	
  C	
  %	
  A	
  	
  
public static void main(String[] args) {
int a , b , c ;
a = 10 ;
b = 20 ;
c = 0 ;
c = a + b ;
System.out.println (c) ;
}
010101010101010101010101	
  
30	
  
Assignment Operators
a = 10 b = 20 c = 0
public static void main(String[] args) {
int a , b , c ;
a = 10 ;
b = 20 ;
c = 0 ;
c + = a ;
System.out.println (c) ;
}
010101010101010101010101	
  
10	
  
Assignment Operators
a = 10 b = 20 c = 0
public static void main(String[] args) {
int a , b , c ;
a = 10 ;
b = 20 ;
c = 0 ;
c - = a ;
System.out.println (c) ;
}
010101010101010101010101	
  
-10	
  
Assignment Operators
a = 10 b = 20 c = 0
public static void main(String[] args) {
int a , b , c ;
a = 10 ;
b = 20 ;
c = 0 ;
c*=a ;
System.out.println (c) ;
}
010101010101010101010101	
  
0	
  
Assignment Operators
a = 10 b = 20 c = 0
public static void main(String[] args) {
int a , b , c ;
a = 10 ;
b = 20 ;
c = 0 ;
c/=a ;
System.out.println (c) ;
}
010101010101010101010101	
  
0	
  
Assignment Operators
a = 10 b = 20 c = 0
public static void main(String[] args) {
int a , b , c ;
a = 10 ;
b = 20 ;
c = 0 ;
c%=a ;
System.out.println (c) ;
}
010101010101010101010101	
  
0	
  
Assignment Operators
a = 10 b = 20 c = 0
Assignment
.٢٥ ، ٢٠ ، ٣٠ : ‫التالية‬ ‫الدرجات‬ ‫مجموع‬ ‫بحساب‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -
. ٧/٢ : ‫قسمة‬ ‫باقي‬ ‫بمعرفة‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -
. ‫راسب‬ ‫او‬ ‫ناجح‬ ‫الطالب‬ ‫كان‬ ‫إذا‬ ‫بمعرفة‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -
) ‫قيمة‬ ‫بطباعة‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -X. ‫الذاكرة‬ ‫في‬ (١ ) ‫بــ‬ ‫القيمة‬ ‫هذه‬ ‫تزويد‬ ‫ذلك‬ ‫بعد‬ ‫ثم‬ ً ‫اوال‬ (
) ‫قيمة‬ ‫بنقص‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -A) ‫قيمة‬ ‫طباعة‬ ‫ذلك‬ ‫بعد‬ ‫ثم‬ ، ‫الذاكرة‬ ‫من‬ (١) ‫بـ‬ (A. (
) ‫بطباعة‬ ‫يقوم‬ ‫برنامج‬ ‫ اكتب‬ -Excellent)‫وطباعة‬ (٩٠ =< X ) ‫كان‬ ‫إذا‬ (Very Good‫(إذا‬
) ‫وطباعة‬ ( ٨٠ =< X ) ‫كان‬Good) ‫وطباعـــــــــــــــة‬ (٥٠ =< X ) ‫كان‬ ‫(إذا‬Fail‫إذا‬ (
.(٥٠ => X ) ‫كان‬

More Related Content

PPTX
Operators
PPTX
Computer programming 2 Lesson 7
PDF
The Ring programming language version 1.6 book - Part 21 of 189
PDF
Java basic operators
PPT
PPT
Operator & Expression in c++
PPTX
Operator.ppt
Operators
Computer programming 2 Lesson 7
The Ring programming language version 1.6 book - Part 21 of 189
Java basic operators
Operator & Expression in c++
Operator.ppt

What's hot (20)

DOCX
C – operators and expressions
PPTX
ZIO: Powerful and Principled Functional Programming in Scala
PPT
6 operators-in-c
PPTX
Operators and Expression
PPT
Mesics lecture 4 c operators and experssions
PPTX
Operators and Expressions in Java
PPTX
Operators and expressions in C++
PPT
Lecture 3
PPTX
Expression and Operartor In C Programming
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
DOCX
Cis 115 Enhance teaching / snaptutorial.com
DOCX
Cis 115 Education Organization -- snaptutorial.com
PPTX
Operators in Java
PPTX
Basic c operators
DOC
CIS 115 Exceptional Education - snaptutorial.com
PPT
Operators and Expressions in C++
PPT
Expressions in c++
PPTX
Operators In Java Part - 8
DOC
Cis 115 Effective Communication / snaptutorial.com
PPT
C operator and expression
C – operators and expressions
ZIO: Powerful and Principled Functional Programming in Scala
6 operators-in-c
Operators and Expression
Mesics lecture 4 c operators and experssions
Operators and Expressions in Java
Operators and expressions in C++
Lecture 3
Expression and Operartor In C Programming
Lecture 2 C++ | Variable Scope, Operators in c++
Cis 115 Enhance teaching / snaptutorial.com
Cis 115 Education Organization -- snaptutorial.com
Operators in Java
Basic c operators
CIS 115 Exceptional Education - snaptutorial.com
Operators and Expressions in C++
Expressions in c++
Operators In Java Part - 8
Cis 115 Effective Communication / snaptutorial.com
C operator and expression
Ad

Viewers also liked (12)

PPTX
Tania ulpo-pe
PPTX
Advance mathematics mid term presentation rev01
PPTX
Pamela bustos- pe
PPTX
Nepal adventure
PPTX
LiveXChange Conference 2013 Animal Welfare Session Dr Leisha Hewitt- Guidelin...
PDF
Part 2
PPT
LiveXChange Conference 2013 Animal Welfare Session Dr Derek Belton- Animal we...
PPTX
TBLT research article _Carless 2004
PDF
Blog (1)
PPTX
TPACK Reflection
PDF
Operating system
PDF
CMD Command prompts
Tania ulpo-pe
Advance mathematics mid term presentation rev01
Pamela bustos- pe
Nepal adventure
LiveXChange Conference 2013 Animal Welfare Session Dr Leisha Hewitt- Guidelin...
Part 2
LiveXChange Conference 2013 Animal Welfare Session Dr Derek Belton- Animal we...
TBLT research article _Carless 2004
Blog (1)
TPACK Reflection
Operating system
CMD Command prompts
Ad

Similar to Java 2 (20)

PPTX
Oop using JAVA
PPTX
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PDF
itft-Operators in java
PDF
Java basic operators
PPTX
Pj01 4-operators and control flow
PPT
object oriented programming java lectures
PDF
10)OPERATORS.pdf
PPTX
presentation on array java program operators
PPTX
Operators in java
PPTX
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
DOCX
Operators
PPTX
Java unit1 b- Java Operators to Methods
PPTX
Opeartor &amp; expression
PPT
4_A1208223655_21789_2_2018_04. Operators.ppt
PPT
operators.ppt
PPTX
Logical Operators C/C++ language Programming
PPT
Java operators
PPTX
Arithmetic Operators ____ java.pptx
PPTX
PPTX
Java chapter 3
Oop using JAVA
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
itft-Operators in java
Java basic operators
Pj01 4-operators and control flow
object oriented programming java lectures
10)OPERATORS.pdf
presentation on array java program operators
Operators in java
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
Operators
Java unit1 b- Java Operators to Methods
Opeartor &amp; expression
4_A1208223655_21789_2_2018_04. Operators.ppt
operators.ppt
Logical Operators C/C++ language Programming
Java operators
Arithmetic Operators ____ java.pptx
Java chapter 3

Recently uploaded (20)

PDF
Pre independence Education in Inndia.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
master seminar digital applications in india
Pre independence Education in Inndia.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
Supply Chain Operations Speaking Notes -ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPH.pptx obstetrics and gynecology in nursing
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
master seminar digital applications in india

Java 2

  • 2. Java Operators The operators in Java are like the following : 1.  Arithme*c  operators  .   2.  Rela*onal  operators.   3.  Logical  operators.   4.  Assignment  operators.  
  • 3. Arithmetic Operators Operator   Descrip-on   Example   +   Addi-on  –  Adds  values  on  either  side  of  the  operator   A + B will give 30 -­‐   Subtrac-on  –  Subtracts  right  hand  from  le?  hand     A - B will give -10 *   Mul-plica-on  -­‐  Mul-plies  values  on  either  side  of  the  operator     A * B will give 200 /   Division  -­‐  Divides  le?  hand  operand  by  right  hand  operand     B / A will give 2 %   Modulus  -­‐  Divides  le?  hand  operand  by  right  hand  operand  and   returns  remainder     B % A will give 0 ++   Increment  -­‐  Increases  the  value  of  operand  by  1     B++ gives 21 -­‐-­‐   Decrement  -­‐  Decreases  the  value  of  operand  by  1     B-- gives 19 Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators: Assume integer variable A holds 10 and variable B holds 20, then:
  • 4. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( A + B ) ; } 010101010101010101010101   30   Addition Operator A=10 B=20
  • 5. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( A - B ) ; } 010101010101010101010101   -10   Subtraction Operator A=10 B=20
  • 6. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( A * B ) ; } 010101010101010101010101   200   Multiplication Operators A=10 B=20
  • 7. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( B / A ) ; } 010101010101010101010101   2   Divition Operator A=10 B=20
  • 8. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( B % A ) ; } 010101010101010101010101   0   Modulus Operator A=10 B=20
  • 9. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( + + B ) ; } 010101010101010101010101   Increment Operator A=10 B=20
  • 10. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( + + B ) ; } 010101010101010101010101   Increment Operator A=10 B=21
  • 11. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( + + B ) ; } 010101010101010101010101   Increment Operator A=10 B=21 21  
  • 12. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println (B + +) ; } 010101010101010101010101   20   Increment Operator A=10 B=20
  • 13. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println (B + +) ; } 010101010101010101010101   20   Increment Operator A=10 B=21
  • 14. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( - - B) ; } 010101010101010101010101   Decrement Operator A=10 B=20
  • 15. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( - - B) ; } 010101010101010101010101   Decrement Operator A=10 B=19
  • 16. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( - - B) ; } 010101010101010101010101   Decrement Operator A=10 B=19 19  
  • 17. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( B - - ) ; } 010101010101010101010101   Decrement Operator A=10 B=20
  • 18. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( B - - ) ; } 010101010101010101010101   20   Decrement Operator A=10 B=20
  • 19. public static void main(String[] args) { int A , B ; A=10 ; B=20 ; System.out.println ( B - - ) ; } 010101010101010101010101   20   Decrement Operator A=10 B=19
  • 20. Relational Operators operator   Descrip-on   Example   ==   Checks  if  the  values  of  two  operands  are  equal  or  not,  if  yes  then   condi-on  becomes  true.                    (equal  )   (A  ==  B)  is  not  true.     !=   Checks  if  the  values  of  two  operands  are  equal  or  not,  if  values  are  not   equal  then  condi-on  becomes  true.                          (  not  equal  )   (A  !=  B)  is  true.     >   Checks  if  the  value  of  le?  operand  is  greater  than  the  value  of  right   operand,  if  yes  then  condi-on  becomes  true.                            (  greater  than)   (A  >  B)  is  not  true.     <   Checks  if  the  value  of  le?  operand  is  less  than  the  value  of  right  operand,   if  yes  then  condi-on  becomes  true.                                            (  Less  than)   (A  <  B)  is  true.     >=   Checks  if  the  value  of  le?  operand  is  greater  than  or  equal  to  the  value  of   right  operand,  if  yes  then  condi-on  becomes  true.     (A  >=  B)  is  not  true.     <=   Checks  if  the  value  of  le?  operand  is  less  than  or  equal  to  the  value  of   right  operand,  if  yes  then  condi-on  becomes  true.     (A  <=  B)  is  true.     There are following relational operators supported by Java language: Assume variable A holds 10 and variable B holds 20 , then:
  • 21. public static void main(String[] args) { int x , y ; x = 10 ; y = 20 ; System.out.println ( x = = y ) ; } 010101010101010101010101   False   Relational Operators x = 10 y = 20
  • 22. public static void main(String[] args) { int x , y ; x = 10 ; y = 20 ; System.out.println ( x ! = y ) ; } 010101010101010101010101   True   Relational Operators x = 10 y = 20
  • 23. public static void main(String[] args) { int x , y ; x = 10 ; y = 20 ; System.out.println ( x > y ) ; } 010101010101010101010101   False   Relational Operators x = 10 y = 20
  • 24. public static void main(String[] args) { int x , y ; x = 10 ; y = 20 ; System.out.println ( x < y ) ; } 010101010101010101010101   True   Relational Operators x = 10 y = 20
  • 25. public static void main(String[] args) { int x , y ; x = 10 ; y = 20 ; System.out.println ( x > = y ) ; } 010101010101010101010101   False   Relational Operators x = 10 y = 20
  • 26. public static void main(String[] args) { int x , y ; x = 10 ; y = 20 ; System.out.println ( x < = y ) ; } 010101010101010101010101   True   Relational Operators x = 10 y = 20
  • 27. Logical Operators Operator   Descrip-on   Example   &&   Called  Logical  AND  operator.  If  both  the  operands   are  non-­‐zero,  then  the  condi-on  becomes  true.     (A  &&  B)  is  false.     ||   Called   Logical   OR   Operator.   If   any   of   the   two   operands  are  non-­‐zero,  then  the  condi-on  becomes   true.     (A  ||  B)  is  true.     !   Called   Logical   NOT   Operator.   Use   to   reverses   the   logical  state  of  its  operand.  If  a  condi-on  is  true  then   Logical  NOT  operator  will  make  false.     !(A  &&  B)  is  true.     The following table lists the logical operators: Assume Boolean variables A holds true and variable B holds false , then:
  • 28. public static void main(String[] args) { int test = 6 ; If ( test = = 9 ) { System.out.println( “ yes ” ) ; } else { System.out.println( “ this is else ” ) ; } } 010101010101010101010101   this is else   If Statement test = 6
  • 29. public static void main(String[] args) { int boy , girl ; boy = 18 ; girl = 68 ; If ( boy > 10 ) { System.out.println(“you can enter”) ; }else{ System.out.println(“you are too young”) } } 010101010101010101010101   You can enter   Logical Operators boy = 18 girl = 68
  • 30. public static void main(String[] args) { int boy , girl ; boy = 18 ; girl = 68 ; If ( boy > 10 && girl < 60 ) { System.out.println(“you can enter”) ; }else{ System.out.println(“you are too young”); } } 010101010101010101010101   You are too young   Logical Operators boy = 18 girl = 68
  • 31. public static void main(String[] args) { int boy , girl ; boy = 18 ; girl = 68 ; If ( boy > 10 | | girl < 60 ) { System.out.println(“you can enter”) ; }else{ System.out.println(“you are too young”); } } 010101010101010101010101   You can enter   Logical Operators boy = 18 girl = 68
  • 32. public static void main(String[] args) { int boy , girl ; boy = 18 ; girl = 68 ; If (!( boy > 10 && girl < 60 )) { System.out.println(“you can enter”) ; }else{ System.out.println(“you are too young”); } } 010101010101010101010101   you can enter   Logical Operators boy = 18 girl = 68
  • 33. public static void main(String[] args) { int age ; age = 3 ; Switch( age ) { case1 : System.out.println(“you can crawl”) ; break ; case2 : System.out.println(“you can talk”) ; break ; case3 : System.out.println(“you can get in trouble”) ; break ; default : System.out.println(“I don’t know how old are you”) } 010101010101010101010101   you can get in trouble   Logical Operators age= 3
  • 34. Assignment Operators Operator   Descrip-on   Example   =   Simple   assignment   operator,   Assigns   values   from   right  side  operands  to  le?  side  operand     C  =  A  +  B  will  assign  value  of     A  +  B  into  C     +=   Add  AND  assignment  operator,  It  adds  right  operand   to   the   le?   operand   and   assign   the   result   to   le?   operand   C  +=  A  is  equivalent  to  C  =  C  +  A   -­‐=   Subtract  AND  assignment  operator,  It  subtracts  right   operand  from  the  le?  operand  and  assign  the  result   to  le?  operand     C  -­‐=  A  is  equivalent  to  C  =  C  -­‐  A     *=   Mul-ply   AND   assignment   operator,   It   mul-plies   right  operand  with  the  le?  operand  and  assign  the   result  to  le?  operand     C  *=  A  is  equivalent  to  C  =  C  *  A     /=   Divide   AND   assignment   operator,   It   divides   le?   operand  with  the  right  operand  and  assign  the  result   to  le?  operand       C  /=  A  is  equivalent  to  C  =  C  /  A   %=   Modulus   AND   assignment   operator,   It   takes   modulus  using  two  operands  and  assign  the  result  to   le?  operand   C  %=  A  is  equivalent  to  C  =  C  %  A    
  • 35. public static void main(String[] args) { int a , b , c ; a = 10 ; b = 20 ; c = 0 ; c = a + b ; System.out.println (c) ; } 010101010101010101010101   30   Assignment Operators a = 10 b = 20 c = 0
  • 36. public static void main(String[] args) { int a , b , c ; a = 10 ; b = 20 ; c = 0 ; c + = a ; System.out.println (c) ; } 010101010101010101010101   10   Assignment Operators a = 10 b = 20 c = 0
  • 37. public static void main(String[] args) { int a , b , c ; a = 10 ; b = 20 ; c = 0 ; c - = a ; System.out.println (c) ; } 010101010101010101010101   -10   Assignment Operators a = 10 b = 20 c = 0
  • 38. public static void main(String[] args) { int a , b , c ; a = 10 ; b = 20 ; c = 0 ; c*=a ; System.out.println (c) ; } 010101010101010101010101   0   Assignment Operators a = 10 b = 20 c = 0
  • 39. public static void main(String[] args) { int a , b , c ; a = 10 ; b = 20 ; c = 0 ; c/=a ; System.out.println (c) ; } 010101010101010101010101   0   Assignment Operators a = 10 b = 20 c = 0
  • 40. public static void main(String[] args) { int a , b , c ; a = 10 ; b = 20 ; c = 0 ; c%=a ; System.out.println (c) ; } 010101010101010101010101   0   Assignment Operators a = 10 b = 20 c = 0
  • 41. Assignment .٢٥ ، ٢٠ ، ٣٠ : ‫التالية‬ ‫الدرجات‬ ‫مجموع‬ ‫بحساب‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ - . ٧/٢ : ‫قسمة‬ ‫باقي‬ ‫بمعرفة‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ - . ‫راسب‬ ‫او‬ ‫ناجح‬ ‫الطالب‬ ‫كان‬ ‫إذا‬ ‫بمعرفة‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ - ) ‫قيمة‬ ‫بطباعة‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -X. ‫الذاكرة‬ ‫في‬ (١ ) ‫بــ‬ ‫القيمة‬ ‫هذه‬ ‫تزويد‬ ‫ذلك‬ ‫بعد‬ ‫ثم‬ ً ‫اوال‬ ( ) ‫قيمة‬ ‫بنقص‬ ‫يقوم‬ ‫برنامج‬ ‫ أكتب‬ -A) ‫قيمة‬ ‫طباعة‬ ‫ذلك‬ ‫بعد‬ ‫ثم‬ ، ‫الذاكرة‬ ‫من‬ (١) ‫بـ‬ (A. ( ) ‫بطباعة‬ ‫يقوم‬ ‫برنامج‬ ‫ اكتب‬ -Excellent)‫وطباعة‬ (٩٠ =< X ) ‫كان‬ ‫إذا‬ (Very Good‫(إذا‬ ) ‫وطباعة‬ ( ٨٠ =< X ) ‫كان‬Good) ‫وطباعـــــــــــــــة‬ (٥٠ =< X ) ‫كان‬ ‫(إذا‬Fail‫إذا‬ ( .(٥٠ => X ) ‫كان‬