◕ **A new product.**

Popular Google Pages:

This article is regarding **Mixed Arithmetic Expressions in Java.**

Last updated on: 22nd March 2017.

◕ Mixed Arithmetic Expressions in Java.

- Let have an example first.

float firstTemp = 10.3;

double secondTemp = 15.4;

long averageTemp = 0;

averageTemp = ( firstTemp + secondTemp ) / 2;

In the above case we have mixed three types of floating point number.

These are **float, double, long.**
If we want to find the **averageTemp** then what type it wii be?

Will it remain as **long ** or it will convert to some other type?

There are some rules for this.

■ 1) If either operand is of type double, the other operand will converted to double before the operation is carried out.

■ 2) If either operand is of type float, the other operand will converted to float before the operation is carried out.

■ 3) If either operand is of type long, the other operand will converted to long before the operation is carried out.

◕ Now what will happen if **type int, short, byte** are mixed?

- In that case they will convert to **type int** and will use 32-bit arithmetic to produce the result.

Related article.
Error in int type

Related Java articles:

■ What is Java? Where we can apply Java?

■ Why Java is a Machine Independent Program? What is Machine Independent Program?

■ Root Directory of Java

■ How to Compile and run a Java Program?

■ What is .class file in Java?

■ What is variable in a program?

■ What is identifier in Java?

■ Integer data types in Java?

■ What is Primitive Types in Java?

■ How to declare constant variables in Java?

■ Why should we declare the initial value of a variable in Java?

■ Use of Underscores to write an integer in Java

Popular Google Pages:

Top of the page