How do I use increment in calculations?

{int num1 = 5;
 int num2 = 6;
 int num3;
 num3 = ++num2 * num1 / num2 + num2;
 System.out.println(num3);} //12 

The compiler gives the num3 = 12, but how do I get that value? when I try to get that num3 value I got 6(by without using compiler). Both value of num2++ and ++num2 gives the same, but when I use following code it gives a different value. Why I got different values. what are the steps for get those num3 values (without using compiler?)

num3 = num2++ * num1 / num2 + num2; //11


Both increment operation num++ and ++num will result into num=num+1 there is only difference between the order of assignment and increment operations.

num++(post-increment) -> first num is used and then incremented ++num(pre-increment) -> first num is incremented and then used

You code prints 12 when I tested.

public static void main(String[] args) {
        int num1 = 5;
        int num2 = 6;
        int num3;
        num3 = ++num2 * num1 / num2 + num2;

I will suggest you to make use of brackets as it will increase readability as well.

Need Your Help

Cross domain ajax request issue

jquery ajax json jsonp

I need to get the json data from the cross domain.

how to make handsontable grid RTL?

jquery html css grid handsontable

I have used handsontable script to create a dynamic grid, but my grid must a RTL.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.