borkins

Exam Jan-2016 - 03. Point on Segment

May 11th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. /**
  2.  * Project: Exam_101_January_2016 - created by borkins on 2017-05-03.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _03_PointOnSegment
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int first = Integer.parseInt(console.nextLine());
  14.         int second = Integer.parseInt(console.nextLine());
  15.         int point = Integer.parseInt(console.nextLine());
  16.        
  17.         int diffFirst = Math.abs(point - first);
  18.         int diffSecond = Math.abs(point - second);
  19.    
  20.         if (first < second) {
  21.             System.out.println((point >= first && point <= second) ? "in" : "out");
  22.         }
  23.         else {
  24.             System.out.println((point >= second && point <= first) ? "in" : "out");
  25.         }
  26.    
  27.         System.out.println((diffFirst < diffSecond) ? diffFirst : diffSecond);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment