Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Math.abs(b - a) + Math.abs(b - c) == c - a // с учётом, что всегда c >= a, иначе Math.abs(c - a)
- boolean membership = ((b - a) * (c - b) >= 0);
- public class Solution
- {
- public static void main(String[] args)
- {
- int[][] tests =
- {
- { 1, 2, 3 },
- { 5, 7, 10 },
- { 4, 4, 11 },
- { 17, 25, 25 },
- { 2, 1, 3 },
- { 17, 25, 24 }
- };
- for (int[] v : tests)
- {
- int a = v[0], b = v[1], c = v[2];
- boolean membership = ((b - a) * (c - b) >= 0);
- System.out.format("(%d, %d, %d) => %bn", a, b, c, membership);
- }
- }
- }
- public static void main(String[] args) {
- int a=1,b=2,c=3;
- if(new Segment(a,c).isEnter(b)){
- System.out.println("Входит");
- }else{
- System.out.println("Не входит");
- }
- }
- static class Segment{
- int a,c;
- public Segment(int a, int c) {
- this.a = a;
- this.c = c;
- }
- public boolean isEnter(int b) {
- return a<=b&&c>=b;
- }
- }
Add Comment
Please, Sign In to add comment