This week's book giveaway is in the Design forum. We're giving away four copies of Building Microservices and have Sam Newman on-line! See this thread for details.

can someone explain what is the difference between these two ? System.out.println(Math.round(3.5)); //4 System.out.println(Math.round(-3.5)); //-3 why what is the logic behind this ?

Basically: Java Math.round() which by the way returns long always leans towards higher number in case of those in the midle like : 2.5, 3.5, -2.5, -3.5. so if you have -5.5 first highest integer/non-decimal is -5. if you have 6.5 it takes first highest integer which is 7. Tarik