Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Samuel Leonte
- Lab 4 Part 1: Points in a rectangle
- This program works by the user entering an x and a y value to make a point.
- The program checks if the x and y are in the rectangle by using the provided formulas
- put into two seperate booleans. If the booleans both return true, then the point is in the rectangle.
- If either or both of the booleans return false, the point is not in the rectangle.
- */
- import java.util.Scanner;
- public class Lab4P1 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter X: ");
- int inputX = input.nextInt();
- System.out.print("Enter Y: ");
- int inputY = input.nextInt();
- boolean correctHorizontalDistance = (inputX <= (10/2));
- boolean correctVerticalDistance = (inputY <= (5/2));
- if ((correctHorizontalDistance) && (correctVerticalDistance)) {
- System.out.println("Point (" + inputX + "," + inputY + ") is in the rectangle.");
- }
- else {
- System.out.println("Point (" + inputX + "," + inputY + ") is not in the rectangle.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement