Advertisement
LeonteS20

Lab4P1.java

Mar 26th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. /*
  2. Samuel Leonte
  3. Lab 4 Part 1: Points in a rectangle
  4.  
  5. This program works by the user entering an x and a y value to make a point.
  6. The program checks if the x and y are in the rectangle by using the provided formulas
  7. put into two seperate booleans. If the booleans both return true, then the point is in the rectangle.
  8. If either or both of the booleans return false, the point is not in the rectangle.
  9. */
  10.  
  11. import java.util.Scanner;
  12. public class Lab4P1 {
  13.     public static void main(String[] args) {
  14.        
  15.         Scanner input = new Scanner(System.in);
  16.         System.out.print("Enter X: ");
  17.         int inputX = input.nextInt();
  18.         System.out.print("Enter Y: ");
  19.         int inputY = input.nextInt();
  20.    
  21.         boolean correctHorizontalDistance = (inputX <= (10/2));
  22.         boolean correctVerticalDistance = (inputY <= (5/2));
  23.        
  24.         if ((correctHorizontalDistance) && (correctVerticalDistance)) {
  25.             System.out.println("Point (" + inputX + "," + inputY + ") is in the rectangle.");
  26.         }
  27.         else {
  28.             System.out.println("Point (" + inputX + "," + inputY + ") is not in the rectangle.");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement