Thursday, October 26, 2017

Java Postfix Operators (increment Operators ++ and Decrement Operators --)

Hi All,

Today I'm going to teach how to use Post-fix Operators in Java, There are two postfix operators increment Operators and Decrement Operators .

Increment Operators

Increment Operators symbolize by using ++ and use to increments variable value by one.


Decrement Operators

Decrement Operators symbolize by using -- and use to decrements variable value by one.

Let's see how these operators works in code,



Some confusing thing happens at the first time we use x++ and x-- it will print originally assigned vale and the change the value.

I will explain you what is really happens when we use those operator in upcoming post. For programming purpose I will explain it as follows.

This is not what really happens when we use these operators

think this operation excite form left to right so as soon as x passes excite process will take x value as 100 then it passes ++ then it increment x by 1 so from the next line onward x is 101

think this operation excite form left to right so as soon as y passes excite process will take y value as 10 then it passes -- then it decrements y by 1 so from the next line onward y is 9

Catch you guys on next post bye...!

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....

Friday, October 20, 2017

Division Operator In Java

Hi All,

Today I'm going to teach you guys how to use division operator in Java. As we know division operator use to divide basically two number and get the answer. Symbol of division operator is / in java and most of other programming languages. In natural languages we use same symbol but there are some different ways people use to write it with numbers to symbolize division operation.

ex
½  1/2

Following is some mathematical examples for how to use division operator

ex

1/2 = 0.5
3/4 = 0.75
2/4 = 0.5

Let's see how to do this 



x = 1 and y = 2 so x/y must be 0.5 but we got 0 as the answer why is this happening ?

by default compiler take answers of integer variables' operation as int so int data type can't keep floating point so it will return the only integer value it has as 0

we can fix this by casting x and y to double.


If we use double variables we can also fix that issue.


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