Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Chap3_23PointInRectangle {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- System.out.println("Enter the x and y coordinates");
- // get user input
- int x = kb.nextInt();
- int y = kb.nextInt();
- int width = 10;
- int height = 5;
- // compute horizontal and vertical distances
- xDist= Math.sqrt((x-0)*(x-0));
- yDist= Math.sqrt((y-0)*(y-0));
- if (xDist < width/2.0 && yDist < height/2.0)
- System.out.println("The point is inside the rectangle");
- else
- System.out.println("The point is outside the rectangle");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement