正方形_JAVA
Description
給出四個(gè)點(diǎn),判斷這四個(gè)點(diǎn)能否構(gòu)成一個(gè)正方形。
Input
輸入的第一行包含一個(gè)整數(shù)T(T≤30)表示數(shù)據(jù)組數(shù),每組數(shù)據(jù)只有一行,包括8個(gè)整數(shù)x1, y1, x2, y2,x3,y3,x4,y4(數(shù)據(jù)均在-1000,1000 之間)以逆時(shí)針順序給出四個(gè)點(diǎn)的坐標(biāo)。
Output
每組數(shù)據(jù)輸出一行,如果是正方形,則輸出: YES, 否則,輸出:NO。
Sample
Input
2
0 0 1 0 1 1 0 1
-1 0 0 -2 1 0 2 0
Output
YES
NO
Hint
import java.util.*;class square {int x1, x2, x3, x4, y1, y2, y3, y4;public void judge() {int f = 0;if (Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) != Math.pow(x1 - x4, 2) + Math.pow(y1 - y4, 2)|| Math.pow(x3 - x2, 2) + Math.pow(y3 - y2, 2) != Math.pow(x3 - x4, 2) + Math.pow(y3 - y4, 2)|| Math.pow(x4 - x2, 2) + Math.pow(y4 - y2, 2) != Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2)) {f = 1;}if (f == 1) {System.out.println("NO");} else {System.out.println("YES");}} }public class Main {public static void main(String[] args) {Scanner reader = new Scanner(System.in);int a = reader.nextInt();while (a-- > 0) {square b = new square();b.x1 = reader.nextInt();b.y1 = reader.nextInt();b.x2 = reader.nextInt();b.y2 = reader.nextInt();b.x3 = reader.nextInt();b.y3 = reader.nextInt();b.x4 = reader.nextInt();b.y4 = reader.nextInt();b.judge();}reader.close();}} 《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
- 上一篇: 手机键盘_JAVA
- 下一篇: 最大矩形面积_JAVA