Pure and mixed expressions – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Code Learning #JAVA#3746 siteicon   siteicon   siteicon  

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

TC++ #3746

Source Code

Run Output

Output c = 8.607693

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



Share

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






Back