Nearest multiple of 10 Java
PROGRAM TO ROUND THE GIVEN NUMBER TO NEAREST MULTIPLE OF 10
OUTPUT
4720
import java.util.*;class MAIN { // function to round the number static int round(int n) { // Smaller multiple int a = (n / 10) * 10; // Larger multiple int b = a + 10; // Return of closest of two return (n - a > b - n)? b : a; } /* Driver program to test above function */ public static void main(String[] args) { int n = 4722; System.out.println(round(n)); }}
4720
Comments
Post a Comment