Advertisement
Guest User

1

a guest
Jan 30th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public class Solution {
  2. public static void main(String[] args) {
  3. displayClosestToTen(8, 11);
  4. displayClosestToTen(7, 14);
  5. //displayClosestToTen(5, 15);
  6. }
  7.  
  8. public static void displayClosestToTen(int a, int b) {
  9. // напишите тут ваш код
  10.  
  11. if (abs(a-10) < abs(b-10)) {
  12. System.out.println(a);
  13. }
  14.  
  15. else if (abs(a-10) > abs(b-10)) {
  16. System.out.println(b);
  17. }
  18.  
  19. else if (abs(a-10) == abs(b-10)) {
  20. System.out.println(a);
  21. }
  22.  
  23.  
  24. }
  25.  
  26. public static int abs(int a) {
  27. if (a < 0) {
  28. return -a;
  29. } else {
  30. return a;
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement