static int round(int n){
          int a = (n / 10) * 10;
          int b = a + 10;
      
          return (n - a > b - n)? b : a;
        }
      

      Java language logoRound the number to nearest ten

      Java Recipes

      In the round() function, a is the integer that represents the number being rounded off to. The expression a + 10 will round the number off to the nearest integer, which in this case is 11. So, the return statement will return 11, as opposed to the original 10.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.