Created
October 18, 2015 12:35
-
-
Save StrixG/7c8ca7c1aa7e8c470a47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.geom.Point2D; | |
import java.util.Scanner; | |
public class Training { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int[][] vertexCoordinates = new int[3][2]; | |
for (int side = 0; side < vertexCoordinates.length; side++) { | |
for (int i = 0; i < vertexCoordinates[side].length; i++) { | |
vertexCoordinates[side][i] = in.nextInt(); | |
} | |
} | |
double[] sideLength = getSideLength(vertexCoordinates); | |
double sum = 0; | |
for (double aSideLength : sideLength) { | |
sum += aSideLength; | |
} | |
System.out.printf("%.6f", sum); | |
} | |
public static double[] getSideLength(int[][] vertexCoordinates) | |
{ | |
double[] sideLength = new double[3]; | |
for (int side = 0; side < sideLength.length; side++) { | |
int nextSide = side + 1; | |
if (nextSide == 3) { | |
nextSide = 0; | |
} | |
sideLength[side] = Point2D.distance(vertexCoordinates[side][0], vertexCoordinates[side][1], vertexCoordinates[nextSide][0], vertexCoordinates[nextSide][1]); | |
} | |
return sideLength; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment