diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-08-01 23:18:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-01 23:18:03 +0100 |
| commit | a3e732f66fb9a452ae71426387da96054cdd1e4f (patch) | |
| tree | 784fcf7fa8816e905167d3d2d57935df16ad0046 /challenge-123/abigail/java/ch-2.java | |
| parent | ed823b76e3a2dd399df5a2cf9ef6434c166f197c (diff) | |
| parent | cd7bc7d98cfd02ca52521e6fa745da216159083e (diff) | |
| download | perlweeklychallenge-club-a3e732f66fb9a452ae71426387da96054cdd1e4f.tar.gz perlweeklychallenge-club-a3e732f66fb9a452ae71426387da96054cdd1e4f.tar.bz2 perlweeklychallenge-club-a3e732f66fb9a452ae71426387da96054cdd1e4f.zip | |
Merge pull request #4642 from Abigail/abigail/week-123
Abigail/week 123
Diffstat (limited to 'challenge-123/abigail/java/ch-2.java')
| -rw-r--r-- | challenge-123/abigail/java/ch-2.java | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/challenge-123/abigail/java/ch-2.java b/challenge-123/abigail/java/ch-2.java index 8d13bcf8bf..24f7dbe9a9 100644 --- a/challenge-123/abigail/java/ch-2.java +++ b/challenge-123/abigail/java/ch-2.java @@ -9,6 +9,9 @@ import java.util.*; public class ch2 { + static int dist (int x1, int y1, int x2, int y2) { + return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); + } public static void main (String [] args) { Scanner scanner = new Scanner (System . in); while (scanner . hasNext ()) { @@ -21,15 +24,11 @@ public class ch2 { int x4 = scanner . nextInt (); int y4 = scanner . nextInt (); - int e1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); - int e2 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3); - int e3 = (x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4); - int e4 = (x4 - x1) * (x4 - x1) + (y4 - y1) * (y4 - y1); - int d1 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3); - int d2 = (x2 - x4) * (x2 - x4) + (y2 - y4) * (y2 - y4); - - System . out . println (e1 == e2 && e2 == e3 && - e3 == e4 && d1 == d2 ? 1 : 0); + System . out . println ( + dist (x1, y1, x2, y2) == dist (x2, y2, x3, y3) && + dist (x2, y2, x3, y3) == dist (x3, y3, x4, y4) && + dist (x3, y3, x4, y4) == dist (x4, y4, x1, y1) && + dist (x1, y1, x3, y3) == dist (x2, y2, x4, y4) ? 1 : 0); } } } |
