Advertisement
shorti

Points inside the house (Java)

May 15th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class InsideOutsideHouse09 {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         float x = input.nextFloat();
  7.         float y = input.nextFloat();
  8.         boolean answer;
  9.         byte position = (byte) ((17.5-12.5)*(y-8.5) - (3.5-8.5)*(x-12.5));
  10.         byte secondPosition = (byte) ((17.5-22.5)*(y-8.5) - (3.5-8.5)*(x-22.5));
  11.        
  12.         if (position >= 0 && y <= 8.5 && secondPosition <= 0) {
  13.             answer = true;
  14.         }
  15.         else if (x >= 12.5 && x <= 17.5 && y <= 13.5 && y >= 8.5) {
  16.             answer = true;
  17.         }
  18.         else if (x >= 20 && x <= 22.5 && y <= 13.5 && y >= 8.5) {
  19.             answer = true;
  20.         }
  21.         else {
  22.             answer = false;
  23.         }
  24.        
  25.         if (answer) {
  26.             System.out.println("Inside");
  27.         }
  28.         else {
  29.             System.out.println("Outside");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement