## Pure and mixed expressions

Forming expressions with operands of same data type and mixed data types.

## Learning Objectives

- Understanding expressions with same data type operands or mixed data type operands.

## Source Code

`class PureMixedExp`

{

public static void main(String[] args)

{

int a=5,b=6;

int c=a+b-b%a;

double x=3.5,y=4.5;

double z=x+y*y;

double m=c+z/a;

System.out.println("Output from pure integer arithmetic expression = "+c);

System.out.println("Output from pure real arithmetic expression = "+z);

System.out.println("Output from mixed arithmetic expression = "+m);

}

}

## Run Output

## Code Understanding

**int a=5, b=6;** //Two integer variable declared and initialised

**int c=a+b-b%a;**

Expression on right of assignment is PURE as it has all operands as integer only. This is called “pure integer arithmetic expression”

**double x=3.5,y=4.5;** //Two double variable declared and initialised

**double z=x+y*y;**

Expression on right of assignment is also PURE as it has all operands as double type only. This is called “pure real arithmetic expression”

**double m=c+z/a;**

Expression on right of assignment is MIXED as it has operands **c** and **a** which are integer and operand **z** which is double. This is called “mixed arithmetic expression”

**System.out.println(“Output from pure integer arithmetic expression = “+c);**

** System.out.println(“Output from pure real arithmetic expression = “+z);**

** System.out.println(“Output from mixed arithmetic expression = “+m); **

Expression outputs are printed here with suitable comment.

**Suggested Filename(s): **PureMixedExp.java

sunmitra| Created: 5-Mar-2018 | Updated: 5-Mar-2018|