Advertisement
therrontelford

Point inside rectangle

Nov 12th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Chap3_23PointInRectangle {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner kb = new Scanner(System.in);
  6.         System.out.println("Enter the x and y coordinates");
  7.  
  8.         // get user input
  9.         int x = kb.nextInt();
  10.         int y = kb.nextInt();
  11.  
  12.         int width = 10;
  13.         int height = 5;
  14.  
  15.         // compute horizontal and vertical distances
  16.         xDist= Math.sqrt((x-0)*(x-0));
  17.         yDist= Math.sqrt((y-0)*(y-0));
  18.        
  19.         if (xDist < width/2.0 && yDist < height/2.0)
  20.             System.out.println("The point is inside the rectangle");
  21.         else
  22.             System.out.println("The point is outside the rectangle");
  23.  
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement