Skip to content

Instantly share code, notes, and snippets.

@yasincidem
Created November 10, 2016 16:09
Show Gist options
  • Save yasincidem/8000c60387363a5e1b5e73ae6283afd5 to your computer and use it in GitHub Desktop.
Save yasincidem/8000c60387363a5e1b5e73ae6283afd5 to your computer and use it in GitHub Desktop.
areaofcircle
Scanner input = new Scanner(System.in);
int[] circle = new int[6];
System.out.print("Enter circle's (x1,y1) (x2,y2) (x3,y3) coordinates ( like this ->1 2 3 4 5 6)--->");
circle[0] = input.nextInt();
circle[1] = input.nextInt();
circle[2] = input.nextInt();
circle[3] = input.nextInt();
circle[4] = input.nextInt();
circle[5] = input.nextInt();
double r;
slope1 = (circle[3] - circle[1]) / (circle[2] - circle[0]);
slope2 = (circle[5] - circle[3]) / (circle[4] - circle[2]);
double xcomp = (((slope1 * slope2) * (circle[1] - circle[5])) + slope2*(circle[0]+circle[2]) - slope1*(circle[2]+circle[4])) / (2*(slope2-slope1));
double ycomp = ((-1 / slope1)*(xcomp-(circle[0]+circle[2])/2)) +(circle[1]+circle[3])/2 ;
r = (int) Math.sqrt((circle[2] - xcomp) * (circle[2] - xcomp) + (circle[3] - ycomp) * (circle[3] - ycomp));
boolean equation = ((circle[3] - circle[1]) * (circle[4] - circle[2])) != ((circle[5] - circle[3]) * (circle[2] - circle[0]));
if (equation) {
System.out.print("(" + circle[0] + "," + circle[1] + ")" + " (" + circle[2] + "," + circle[3] + ")" + " (" + circle[4] + "," + circle[5] + ") ");
System.out.print(" coordinates form a circle ");
System.out.println("and the area of the circle is " + r * r * 3.14 + "cm2");
} else if (circle[0] == circle[2] && circle[0] == circle[4] /*&& numbers[2]==numbers[4]*/) {
System.out.print("(" + circle[0] + "," + circle[1] + ")" + " (" + circle[2] + "," + circle[3] + ")" + " (" + circle[4] + "," + circle[5] + ") ");
System.out.println(" coordinates do not form a circle ");
}
else if (circle[1] == circle[3] && circle[1] == circle[5]) {
System.out.print("(" + circle[0] + "," + circle[1] + ")" + " (" + circle[2] + "," + circle[3] + ")" + " (" + circle[4] + "," + circle[5] + ") ");
System.out.println(" coordinates do not form a circle ");
}
else
{
System.out.print("(" + circle[0] + "," + circle[1] + ")" + " (" + circle[2] + "," + circle[3] + ")" + " (" + circle[4] + "," + circle[5] + ") ");
System.out.println(" coordinates do not form a circle ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment