Nlp-Ai Java Lecture No. 4: Operators & Decision Constructs
Nlp-Ai Java Lecture No. 4: Operators & Decision Constructs
• Increment Operator
• Decrement Operator
• Boolean Data Type
• Relational Operators
• Equality Operators
• Conditional Operators
• Selectional Constructs
03 August 2004
nlp-ai@cse.iitb
Increment Operators
03 August 2004
nlp-ai@cse.iitb
Decrement Operators
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
Boolean Data Type
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,
Refer to bool_op.java
03 August 2004
nlp-ai@cse.iitb
Relational Operators
03 August 2004
nlp-ai@cse.iitb
Equality Operators
Refer: equa.java
03 August 2004
nlp-ai@cse.iitb
Conditional Operators
•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
03 August 2004
nlp-ai@cse.iitb
The ‘ if ’ construct
Thank You!
03 August 2004
nlp-ai@cse.iitb