Can You Divide a Double by an Int Java

division

In elementary school, we learned partition:

6 / 2 = 3,

12 / half dozen = two

And then on.

Sectionalization makes sense. Merely how about modern division ? What is that? It fifty-fifty sounds a bit scary. But in fact, it'south very like shooting fish in a barrel. Allow's acquire about it. The first thing you need to understand is that:

  1. Mod division is an Operator

Yous already know how the improver and subtraction operators work. After you lot finish reading this article, you volition besides empathize for what modernistic sectionalisation does.

operators-vertex-academy-en

  1. In partitioning, we utilize "/", but in mod division, we use%
  2. Sometimes modern partitioning is called mod. So if you see the word "mod," it ways we're talking nearly the Modulus Operator.
  3. What exactly does the operator exercise? The mod partitioning gives the remainder of the division.

Example No. ane

Yous tin split 9 by 4, using:

  • common division, as nosotros were taught in school
  • modernistic segmentation

You now sympathise the logic of how the modulus operator works. Now it'due south time to run an example on your figurer:

If y'all run this code on your computer, you volition see the post-obit number in your console:

1

Example No. 2

You can split 17 by 5, using:

  • mutual sectionalisation, as nosotros were taught in school
  • mod division

And let's run this program on the estimator:

If you run this code on your computer, you will see the following number in the console:

2

Number No. 3

You can split up 21 past 7, using:

  • common division, as nosotros were taught in school
  • mod division

And let's run this program on the reckoner:

If you run this code on your computer, you will the post-obit number in the console:

0

Example No. four

Yous can divide 7.6 past two.ix, using:

  • common division, as nosotros were taught in schoolhouse
  • modernistic division

And let's run this programme on the estimator:

If you run this code on your computer, you lot will see a number close to 1.8 in the panel. Yous may see the number one.7999999999999998. Due to the peculiarities of Coffee, which we will embrace later in other articles, the number may be slightly dissimilar on unlike computers. But it will exist close to the value 1.viii.

Then, every bit you at present empathize, the modulus operator gives the remainder of the division .

  1. Mod division applies to the following types of variables:
  • Byte, short, Int, long – integer variables
  • Bladder, Double – floating point numbers
  • Negative and positive numbers

When you use the modulus operator with negative numbers, you take to follow some eccentric rules.

Take the post-obit steps:

i. Remove the minus sign.

two. Divide the numbers every bit usual.

3. And then, if the first number (the dividend) had a minus sign in forepart of it (before yous removed information technology), then yous bring dorsum the minus sign and put information technology in front end of the result.

Example No. 5

mod-example5-vertex-academy-en

And now let'due south run the program with ane of the examples to a higher place:

If y'all run this code on your computer, you will see the post-obit number in the console:

-1

You now know what mod division in Java is.


fordcluat1994.blogspot.com

Source: https://vertex-academy.com/tutorials/en/dividing-module-java/

0 Response to "Can You Divide a Double by an Int Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel