Day5 : Operators in java
Operators
1) Arithmetic Operator - Addition(+), Subtraction (-), Multiplication(*), Division(/), Modulus(%)
2) Relational Operator - Greater than(>), Less than(<), Greater equal to (>=), Less equal to(<=), equal to(==), not equal to(!=)
3)Logical Operator - AND(&&), OR(||), NOT(!)
4)Increment Operator(Post a++ and pre ++a) and Decrement operator(Post a-- and pre --a)
5)Shorthand Operator : +=, -=, *=, /=, %=
6)Assignment Operator: =
7)Parenthesis: ()
Question on Operator:
int a;
a = 10/4;
Output: 2
...................
int a;
a = 10/4.0;
Error: Possible Lossy Conversion
................
float a;
a = 10/4;
Output: 2.0
..................
float a;
a = 10/4.0;
Error: Possible lossy Conversion
...........
3%2 = 1(Output)
10%4 = 2(Output)
Post Increment (a++):
int a = 10;
int b;
b = a++;
System.out.println(a);
System.out.println(b);
Comments