Saturday, October 21, 2017

Remainder Operator In Java

Hi All,

This post is about Remainder Operator. Not like other Arithmetic Operators we don't use this remainder operator in day to day maths. This is a kind of special operator for programming languages. This remainder operator symbolized by using % sign. Following example will show you how this remainder operator works.

ex

10 % 6 = 4
5 % 5 = 0
5 % 2 = 1

As you can see this operation will give us remaining value after division.

Let's try this in code.




Following is some special case


When we try to get the answer for 10%17 we get 10 this is a normal thing if you guys remember 
long division. When we using long division for above case,

1) Find number of 17s in 10 answer is 0
2) Then 10 - (0 * 17) = 10

Let's see how Remainder Operator works with double values


When we use double vales we get the answer with the floating points.

Catch you guys in my next post bye....

1 comment:

  1. Create a program that will ask personal information and display that information in one line

    ReplyDelete