Explain arithmetic promotion and binary operations, JAVA Programming

Assignment Help:

Explain Arithmetic Promotion and Binary Operations?

An int divided through an int is an int, and a double divided by a double is a double, but what about an int divided by a double or a double divided by an int? When doing arithmetic on not like types Java tends to widen the types includes so as to prevent losing information. After all 3 * 54.2E18 will be a perfectly valid double but much too big for any int.

The primary rule is that if either of the variables in a binary operation (addition, multiplication, subtraction, addition, remainder) are doubles then Java treats both values as doubles. If neither value is a double but one is a float, then Java treats both values as floats. If neither is a float or a double but one is a long, then Java treats both values as longs. At last if there are no doubles, floats or longs, then Java treats both values as an int, even if there aren't any ints in the equation. Thus the result will be a double, float, long or int depending on the kinds of the arguments.


Related Discussions:- Explain arithmetic promotion and binary operations

Decsion tree, implementation of DT in netbeans

implementation of DT in netbeans

What is an immutable object, What is an immutable object? An immutable ...

What is an immutable object? An immutable object is one that we can't change once it's created. Steps involved in creation of an immutable object are: Make all of its data f

Information retrieval during multi-agent system, Information Retrieval duri...

Information Retrieval during Multi-Agent System with Data Mining in Cloud Computing Project Description: I have proposed one research model on "Information Retrieval during M

What are the difference between throw and throws, What are the difference b...

What are the difference between throw and throws? Differences are between throws and throw are: Throw is employed to trigger an exception while throws is used in declara

Create an application for Koch’s Cottages, Create an application for Koch’s...

Create an application for Koch’s Cottages, a weekend getaway resort that rents cottages and boats to use on the local lakenimum 100 words accepted#

Object-based programming, JavaScript is an extremely powerful object-based ...

JavaScript is an extremely powerful object-based (or prototype-based) language. It is not a full-blown OOP (Object-Oriented Programming) language, like Java, however it is an objec

Describe even higer dimensions in java, Describe even higer dimensions in j...

Describe even higer dimensions in java? You don't have to stop along with two dimensional arrays. Java allows arrays of three, four or more dimensions. Therefore chances are pr

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd