Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*3.Write a program to check whether a point is inside or outside
- of the figure below. The point is given as a pair of
- floating-point numbers, separated by a space. Your program
- should print "Inside" or "Outside". */
- /*Tests
- 10 9.7 19.693 13.4 15.02 4.83 ans:Outside
- 22.5 8.5 21.45 9.7 12.5 6 ans: Inside */
- import java.util.Scanner;
- public class PointsInsideAFigure {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double x,y;
- System.out.println("Enter coords of the point");
- System.out.println("Enter q to Quit");
- while(true){
- try {
- x = input.nextDouble();
- y = input.nextDouble();
- } catch (Exception e) {
- System.out.println("Bye!");
- break;
- }
- if(x >=12.5 && x <=22.5 && y >=6 && y <=8.5){
- System.out.println("Inside");
- }
- else if(x >=12.5 && x <=17.5 && y >=6 && y <=13.5){
- System.out.println("Inside");
- }
- else if(x >=20 && x <=22.5 && y >=6 && y <=13.5){
- System.out.println("Inside");
- }
- else {
- System.out.println("Outside");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement