1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
public class Segment { private int x; private int y; public Segment(int x, int y) { this.x = x; this.y = y; } public int longueur() { return x < y ? y - x : x - y; } public String toString() { return String.format("Segment [%d, %d]", x, y); } }