Skip to main content

Java: expression.

JAVA.
 
Do you wanted to know what is expression? What are types of expression?to know that read the following carefully and completely to understand.
 
Expression.

Combination of operator, constants and variable is known as Expression.

There are 3 types of expression.
  • Arithmetic expression.
  • Relational expression.
  • Logical expression.

ARITHMETIC EXPRESSION.

Arithmetic expression produce numeric value such as integer, float, double.

    There are 3 modes.
    • Integer arithmetic.
    • Real arithmetic.
    • Mixed arithmetic.

    Integer arithmetic.

If the operands are integer arithmetic operations yield an integer value.

        An integer division is different from ordinary division, because the fraction         part of the quotionis truncated.

    example:
     5/3=1  but actual output is 1.51516.
4/7=0  but actual outout is 0.59123.

    Real Arithmetic.
If the operands are real then the real operations is done, and output will be     floating point value.

    example:
5.0/3.0=1.5.
4.0/7.0=0.5.

    Mixed operation.
  In mixed mode operation, the operant can be of different data types. The         operands are converted into the same data types before the operation.

    example:
4/5+3.1=3.2.
5.5+5=10.5.

RELATIONAL EXPRESSION.

Relational operand are used to compare value of two arithmetic expression.

It produces the result in boolean that is,the out put is either true or false.
    
example:
c=x>y;


LOGICAL EXPRESSION.

Logical expression is used to express logical computation. It produces the result in boolean that is,the out put is either ture or false. 

example:
c=a||b;


EVALUATION OF A VARIABLE.
Expression are evaluated by using assignment statement.
syntax:
variable=expression.
where variable is a user defined name.

when the above is declared, the expression is evaluated first, then the evaluated value is assigned to the variable.

example:
a=x+10/2;
b=(x+y)*2;



Comments