package com.codegym.task.task04.task0409;
/*
Closest to 10
*/
public class Solution {
public static void main(String[] args) {
displayClosestToTen(8, 11);
displayClosestToTen(7, 14);
}
public static void displayClosestToTen(int a, int b) {
// write your code here
int c = a - 10;
abs(c);
int d = b - 10;
abs(d);
if(c < d)
System.out.println(a);
if(d < c)
System.out.println(b);
if(c == d)
System.out.println("Either of them are closest to 10");
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}
package com.codegym.task.task04.task0409;
/*
Closest to 10
*/
public class Solution {
public static void main(String[] args) {
displayClosestToTen(8, 11);
displayClosestToTen(7, 14);
}
public static void displayClosestToTen(int a, int b) {
// write your code here
int c = a - 10;
abs(c);
int d = b - 10;
abs(d);
if(c < d)
System.out.println(a);
if(d < c)
System.out.println(b);
if(c == d)
System.out.println("Either of them are closest to 10");
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}