Guest User

Untitled

a guest
Feb 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Math.abs(b - a) + Math.abs(b - c) == c - a // с учётом, что всегда c >= a, иначе Math.abs(c - a)
  2.  
  3. boolean membership = ((b - a) * (c - b) >= 0);
  4.  
  5. public class Solution
  6. {
  7. public static void main(String[] args)
  8. {
  9. int[][] tests =
  10. {
  11. { 1, 2, 3 },
  12. { 5, 7, 10 },
  13. { 4, 4, 11 },
  14. { 17, 25, 25 },
  15. { 2, 1, 3 },
  16. { 17, 25, 24 }
  17. };
  18.  
  19. for (int[] v : tests)
  20. {
  21. int a = v[0], b = v[1], c = v[2];
  22. boolean membership = ((b - a) * (c - b) >= 0);
  23. System.out.format("(%d, %d, %d) => %bn", a, b, c, membership);
  24. }
  25. }
  26. }
  27.  
  28. public static void main(String[] args) {
  29. int a=1,b=2,c=3;
  30. if(new Segment(a,c).isEnter(b)){
  31. System.out.println("Входит");
  32. }else{
  33. System.out.println("Не входит");
  34. }
  35. }
  36.  
  37.  
  38. static class Segment{
  39. int a,c;
  40. public Segment(int a, int c) {
  41. this.a = a;
  42. this.c = c;
  43. }
  44.  
  45. public boolean isEnter(int b) {
  46. return a<=b&&c>=b;
  47. }
  48. }
Add Comment
Please, Sign In to add comment