Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public static void main(String[] args) {
- displayClosestToTen(8, 11);
- displayClosestToTen(7, 14);
- //displayClosestToTen(5, 15);
- }
- public static void displayClosestToTen(int a, int b) {
- // напишите тут ваш код
- if (abs(a-10) < abs(b-10)) {
- System.out.println(a);
- }
- else if (abs(a-10) > abs(b-10)) {
- System.out.println(b);
- }
- else if (abs(a-10) == abs(b-10)) {
- System.out.println(a);
- }
- }
- public static int abs(int a) {
- if (a < 0) {
- return -a;
- } else {
- return a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement