SlideShare a Scribd company logo
03 August 2004
NLP-AI
Java Lecture No. 4
Operators & Decision Constructs
Satish Dethe
<satishd@cse.iitb.ac.in>
03 August 2004
nlp-ai@cse.iitb
• Increment Operator
• Decrement Operator
• Boolean Data Type
• Relational Operators
• Equality Operators
• Conditional Operators
• Selectional Constructs
Contents
03 August 2004
nlp-ai@cse.iitb
• i + + first use the value of i and then increment it by 1.
‘i + +’ equivalent to ‘i = (i)+1’. // postfix increment
• + + i first increment the value of i by 1 and then use it.
‘+ + i’ equivalent to ‘i = (i+1)’. // prefix increment
int i=2;
•System.out.print(“ i = ”+ i++);//print 2, then i becomes 3
•System.out.print(“ i = ”+ ++i);//add 1 to i, then print 4
•Refer to incre.java
Increment Operators
03 August 2004
nlp-ai@cse.iitb
Decrement Operators
• i - - first use the i ’s value and then decrement it by one
i - - equivalent to (i)-1. // postfix decrement
• - - i first decrement i ’s value by one and then use it.
- - i equivalent to (i-1). // prefix decrement
int i=5;
System.out.print(“i = ” + i--);//print 5, then i becomes 4
System.out.print(“i = ” + --i);//subtract 1 from i, then print 3
Refer to decre.java
03 August 2004
nlp-ai@cse.iitb
This data type can store only two values; true and false.
Declaring a boolean variable is the same as declaring any other
primitive data type like int, float, char.
boolean response = false; //Valid
boolean answer = true; //Valid
boolean answer = 9943; //Invalid,
boolean response = “false”; // Invalid,
This is return type for relational & conditional operators.
Refer to bool_op.java
Boolean Data Type
03 August 2004
nlp-ai@cse.iitb
Relational Operators
a < b a less than b. (true/false)
a <= b a less than or equal b. (true/false)
a > b a greater than b. (true/false)
a >= b a greater than or equal to b. (true/false)
These operations always return a boolean value.
System.out.println(“23 is less than 65 ” +23<65); // true
System.out.println(“5 is greater than or equal to 25.00?” +
5>=25.00); // false
Refer to relate.java
03 August 2004
nlp-ai@cse.iitb
a = = b a equal to b. (true/false)
a ! = b a not equal to b. (true/false)
boolean equal = 12 = = 150; // false
boolean again_equal = ‘r’= = ‘r’); // true
boolean not_equal = 53!=90); // true
Refer: equa.java
Equality Operators
03 August 2004
nlp-ai@cse.iitb
•A conditional operator is used to handle only two boolean
expressions.
Boolean expression always returns ‘true’ or ‘false’.
•Conditional AND ‘&&’
Return value is ‘true’ if both, x and y are true, else it is ‘false’.
System.out.println(“x&&y ” + x&&y); // Refer cond_and.java
•Conditional OR ‘||’
return value is true if any one of x or y, is true else it is false.
System.out.println(“x||y ” + x||y); // Refer cond_or.java
Conditional Operators
03 August 2004
nlp-ai@cse.iitb
nlp-ai@cse.iitb
The ‘ if ’ construct
It is used to select a certain set of instructions. It is used to decide
whether this set is to be carried out, based on the condition in the
parenthesis. Its syntax is:
if (<boolean expression>){
//body starts
<statement(s)>
//body ends
}
The <boolean expression> is evaluated first. If its value is true, then
the statement(s) are executed. And then the rest of the program. Refer
if_cond.java, if_cond1.java
03 August 2004
The ‘if else’ construct
It is used to provide an alternative when the expression in if is
false. Its syntax is:
if(<boolean expression>){
<statement(s)>
}
else{
<statement(s)>
}
The if construct is the same. But when the expression inside if
is false then else part is executed.
Refer ifelse_cond.java
nlp-ai@cse.iitb
03 August 2004
Assignments
int a_number=1; // (range: 1 to 5 including both)
Print the value of a_number in word. For example, it should print
“Four” if a_number contains 4.
1. Use equality ‘= =’ operator.
2. Do not use equality ‘= =’ operator.
nlp-ai@cse.iitb
03 August 2004
nlp-ai@cse.iitb
Thank You!
End

More Related Content

PPTX
Oop using JAVA
PPT
4_A1208223655_21789_2_2018_04. Operators.ppt
PDF
Operators in java
PDF
Java basic operators
PDF
Java basic operators
PPTX
Operators
PDF
Java 2
PPTX
L3 operators
Oop using JAVA
4_A1208223655_21789_2_2018_04. Operators.ppt
Operators in java
Java basic operators
Java basic operators
Operators
Java 2
L3 operators

Similar to java_lect_04 Decision Structures in Java.ppt (20)

PPTX
L3 operators
PPTX
L3 operators
PPTX
Java chapter 3
PPTX
02 Java Language And OOP PART II
PPTX
Pi j1.3 operators
PPTX
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
DOCX
Operators
PPTX
Pj01 4-operators and control flow
PPTX
Arithmetic Operators ____ java.pptx
PPTX
OCA Java SE 8 Exam Chapter 2 Operators & Statements
PPTX
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
PPTX
Computer programming 2 Lesson 7
PPTX
Java Operators with Simple introduction.pptx
PDF
10)OPERATORS.pdf
PPTX
Java Chapter 05 - Conditions & Loops: part 2
PPTX
Java Operators with Simple introduction.pptx
PDF
8- java language basics part2
PDF
itft-Operators in java
PPT
Chapter 2&3 (java fundamentals and Control Structures).ppt
PPT
Data types and Operators
L3 operators
L3 operators
Java chapter 3
02 Java Language And OOP PART II
Pi j1.3 operators
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
Operators
Pj01 4-operators and control flow
Arithmetic Operators ____ java.pptx
OCA Java SE 8 Exam Chapter 2 Operators & Statements
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
Computer programming 2 Lesson 7
Java Operators with Simple introduction.pptx
10)OPERATORS.pdf
Java Chapter 05 - Conditions & Loops: part 2
Java Operators with Simple introduction.pptx
8- java language basics part2
itft-Operators in java
Chapter 2&3 (java fundamentals and Control Structures).ppt
Data types and Operators
Ad

More from javidmiakhil63 (7)

PPTX
Lecture_1_Introduction_to_Operating_Systems.pptx
PPTX
Lecture_2_Process_Management in operating systems.pptx
PPTX
Lec 2 Compiler, Interpreter, linker, loader.pptx
PPTX
Lec 1 Introduction to Programming Concepts.pptx
PPT
06-ControlStatements in Java Loops, If statements, Switch.ppt
PPT
24-BuildingGUIs Complete Materials in Java.ppt
PPT
java_lect_05 Constructors in Java with overloading.ppt
Lecture_1_Introduction_to_Operating_Systems.pptx
Lecture_2_Process_Management in operating systems.pptx
Lec 2 Compiler, Interpreter, linker, loader.pptx
Lec 1 Introduction to Programming Concepts.pptx
06-ControlStatements in Java Loops, If statements, Switch.ppt
24-BuildingGUIs Complete Materials in Java.ppt
java_lect_05 Constructors in Java with overloading.ppt
Ad

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Introduction to Artificial Intelligence
PPTX
ai tools demonstartion for schools and inter college
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
medical staffing services at VALiNTRY
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Operating system designcfffgfgggggggvggggggggg
How Creative Agencies Leverage Project Management Software.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Introduction to Artificial Intelligence
ai tools demonstartion for schools and inter college
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
Softaken Excel to vCard Converter Software.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
medical staffing services at VALiNTRY
Navsoft: AI-Powered Business Solutions & Custom Software Development
wealthsignaloriginal-com-DS-text-... (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

java_lect_04 Decision Structures in Java.ppt

  • 1. 03 August 2004 NLP-AI Java Lecture No. 4 Operators & Decision Constructs Satish Dethe <satishd@cse.iitb.ac.in>
  • 2. 03 August 2004 nlp-ai@cse.iitb • Increment Operator • Decrement Operator • Boolean Data Type • Relational Operators • Equality Operators • Conditional Operators • Selectional Constructs Contents
  • 3. 03 August 2004 nlp-ai@cse.iitb • i + + first use the value of i and then increment it by 1. ‘i + +’ equivalent to ‘i = (i)+1’. // postfix increment • + + i first increment the value of i by 1 and then use it. ‘+ + i’ equivalent to ‘i = (i+1)’. // prefix increment int i=2; •System.out.print(“ i = ”+ i++);//print 2, then i becomes 3 •System.out.print(“ i = ”+ ++i);//add 1 to i, then print 4 •Refer to incre.java Increment Operators
  • 4. 03 August 2004 nlp-ai@cse.iitb Decrement Operators • i - - first use the i ’s value and then decrement it by one i - - equivalent to (i)-1. // postfix decrement • - - i first decrement i ’s value by one and then use it. - - i equivalent to (i-1). // prefix decrement int i=5; System.out.print(“i = ” + i--);//print 5, then i becomes 4 System.out.print(“i = ” + --i);//subtract 1 from i, then print 3 Refer to decre.java
  • 5. 03 August 2004 nlp-ai@cse.iitb This data type can store only two values; true and false. Declaring a boolean variable is the same as declaring any other primitive data type like int, float, char. boolean response = false; //Valid boolean answer = true; //Valid boolean answer = 9943; //Invalid, boolean response = “false”; // Invalid, This is return type for relational & conditional operators. Refer to bool_op.java Boolean Data Type
  • 6. 03 August 2004 nlp-ai@cse.iitb Relational Operators a < b a less than b. (true/false) a <= b a less than or equal b. (true/false) a > b a greater than b. (true/false) a >= b a greater than or equal to b. (true/false) These operations always return a boolean value. System.out.println(“23 is less than 65 ” +23<65); // true System.out.println(“5 is greater than or equal to 25.00?” + 5>=25.00); // false Refer to relate.java
  • 7. 03 August 2004 nlp-ai@cse.iitb a = = b a equal to b. (true/false) a ! = b a not equal to b. (true/false) boolean equal = 12 = = 150; // false boolean again_equal = ‘r’= = ‘r’); // true boolean not_equal = 53!=90); // true Refer: equa.java Equality Operators
  • 8. 03 August 2004 nlp-ai@cse.iitb •A conditional operator is used to handle only two boolean expressions. Boolean expression always returns ‘true’ or ‘false’. •Conditional AND ‘&&’ Return value is ‘true’ if both, x and y are true, else it is ‘false’. System.out.println(“x&&y ” + x&&y); // Refer cond_and.java •Conditional OR ‘||’ return value is true if any one of x or y, is true else it is false. System.out.println(“x||y ” + x||y); // Refer cond_or.java Conditional Operators
  • 9. 03 August 2004 nlp-ai@cse.iitb nlp-ai@cse.iitb The ‘ if ’ construct It is used to select a certain set of instructions. It is used to decide whether this set is to be carried out, based on the condition in the parenthesis. Its syntax is: if (<boolean expression>){ //body starts <statement(s)> //body ends } The <boolean expression> is evaluated first. If its value is true, then the statement(s) are executed. And then the rest of the program. Refer if_cond.java, if_cond1.java
  • 10. 03 August 2004 The ‘if else’ construct It is used to provide an alternative when the expression in if is false. Its syntax is: if(<boolean expression>){ <statement(s)> } else{ <statement(s)> } The if construct is the same. But when the expression inside if is false then else part is executed. Refer ifelse_cond.java nlp-ai@cse.iitb
  • 11. 03 August 2004 Assignments int a_number=1; // (range: 1 to 5 including both) Print the value of a_number in word. For example, it should print “Four” if a_number contains 4. 1. Use equality ‘= =’ operator. 2. Do not use equality ‘= =’ operator. nlp-ai@cse.iitb