Day5 : Operators in java

 Operators

Operator is  a symbol that is used to perform an operation.

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);


Pre-Increment(++a)

int a = 10;

int b;

b = ++a;

System.out.println(a);

System.out.println(b);





Comments

Popular posts from this blog

Day2 : Compiling Java Program with Examples

Day1: Introduction to Java and its feature

What does System.out.printf( "%-15s%03d\n", s1, x) do?