Define a method which returns the sum of three rounded numbers. If the right most digit of the number is lessthan 5, then round off it's value to the previous multiple of 10 otherwise if the right most digit of the number is greater or equal to 5, then round off to the next multiple of 10.
public class Roundofff { public static void main(String[] args) { int a = 23, b = 34, c = 69; System.out.println(sumOfMultiples(a, b, c)); } public static int sumOfMultiples(int a, int b, int c) { if(a <= 0 && b <= 0 && c <= 0){ return -1; } a = a + (10 - a % 10); b= b + (10 - b % 10); c= c + (10 - c % 10); return a + b +c; } }
public static int Round(int x) { int leastDigit = x % 10; return (x - leastDigit) + (leastDigit < 5 ? 0 : 10); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)