java练习题,判断第二个矩形是否完全在第一个矩形以内,还是两者部分相交、还是相离?
请问这段代码的思维方式Scannerinput=newScanner(System.in);System.out.print("Entercircle1'scenterx...
请问这段代码的思维方式
Scanner input = new Scanner(System.in);
System.out.print("Enter circle1's center x-, y-coordinates, and radius:");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double r1 = input.nextDouble();
System.out.print("Enter circle2's center x-, y-coordinates, and radius:");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double r2 = input.nextDouble();
double temp = Math.pow((x1 - x2), 2) + Math.pow((y2 - y1), 2);
double distance = Math.pow(temp, 0.5);
if (distance <= Math.abs(r1 - r2))
System.out.println("circle2 is inside circle1");
else if (distance <= (r1 + r2))
System.out.println("circle2 overlaps circle1");
else
System.out.println("circle2 does not overlap circle1"); 展开
Scanner input = new Scanner(System.in);
System.out.print("Enter circle1's center x-, y-coordinates, and radius:");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double r1 = input.nextDouble();
System.out.print("Enter circle2's center x-, y-coordinates, and radius:");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double r2 = input.nextDouble();
double temp = Math.pow((x1 - x2), 2) + Math.pow((y2 - y1), 2);
double distance = Math.pow(temp, 0.5);
if (distance <= Math.abs(r1 - r2))
System.out.println("circle2 is inside circle1");
else if (distance <= (r1 + r2))
System.out.println("circle2 overlaps circle1");
else
System.out.println("circle2 does not overlap circle1"); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询