Advertisement
viraldim

PointsInsideAFigure

May 13th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. /*3.Write a program to check whether a point is inside or outside
  2. of the figure below. The point is given as a pair of
  3. floating-point numbers, separated by a space. Your program
  4. should print "Inside" or "Outside". */
  5.  
  6. /*Tests
  7. 10 9.7  19.693 13.4  15.02 4.83 ans:Outside
  8. 22.5 8.5  21.45 9.7  12.5 6    ans: Inside */
  9.  
  10. import java.util.Scanner;
  11.  
  12. public class PointsInsideAFigure {
  13.  
  14.     public static void main(String[] args) {
  15.        
  16.         Scanner input = new Scanner(System.in);
  17.         double x,y;
  18.        
  19.         System.out.println("Enter coords of the point");
  20.         System.out.println("Enter q to Quit");
  21.        
  22.         while(true){
  23.             try {
  24.                 x = input.nextDouble();
  25.                 y = input.nextDouble();
  26.             } catch (Exception e) {
  27.                 System.out.println("Bye!");
  28.                 break;
  29.             }              
  30.            
  31.             if(x >=12.5 && x <=22.5 && y >=6 && y <=8.5){
  32.                 System.out.println("Inside");
  33.             }
  34.             else if(x >=12.5 && x <=17.5 && y >=6 && y <=13.5){
  35.                 System.out.println("Inside");
  36.             }
  37.             else if(x >=20 && x <=22.5 && y >=6 && y <=13.5){
  38.                 System.out.println("Inside");
  39.             }
  40.             else {
  41.                 System.out.println("Outside");
  42.             }
  43.         }      
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement