Introduction to Java Programming编程题3.22<判断点是否在矩形内>

来源:互联网 发布:php 读取文件过程 编辑:程序博客网 时间:2024/06/08 06:00
/*Enter a point with two coordinates: 2 7Point (2.0, 7.0) is not in the rectangle.Enter a point with two coordinates: 2 2Point (2.0, 2.0) is in the rectangle.*/import java.util.Scanner;public class PointInARectagle {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);        double x1 = 10 / 2, y1 = 5 / 2;        System.out.print("Enter a point with two coordinates: ");        double x2 = input.nextDouble();        double y2 = input.nextDouble();        if (x2 <= x1 && y2 <= y1)            System.out.println("Point (" + x2 + ", " + y2 + ")" + " is in the rectangle.");        else            System.out.println("Point (" + x2 + ", " + y2 + ")" + " is not in the rectangle.");    }}
0 0
原创粉丝点击