⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triangle.java

📁 水仙花数是三位数
💻 JAVA
字号:
import java.io.*;
class Point
{
	double x;
	double y;
	
	public Point()
	{
	}
	
	public Point(double x,double y)
	{
		this.x = x;
		this.y = y;
	}
	
	double GetX()
	{
		return x;
	}
		
	double GetY()
	{
		return y;
	}
}

public class Triangle
{
	Point pointA;
	Point pointB;
	Point pointC;
	
	double sideA;
	double sideB;
	double sideC;
	
	public Triangle()
	{
	}
	
	public Triangle(Point aPointA,Point aPointB,Point aPointC)
	{
		this.pointA = aPointA;
		this.pointB = aPointB;
		this.pointC = aPointC;
		this.sideA = Math.sqrt(Math.pow(pointA.GetX() - pointB.GetX(),2) + Math.pow(pointA.GetY() - pointB.GetY(),2));
		this.sideB = Math.sqrt(Math.pow(pointB.GetX() - pointC.GetX(),2) + Math.pow(pointB.GetY() - pointC.GetY(),2));
		this.sideC = Math.sqrt(Math.pow(pointC.GetX() - pointA.GetX(),2) + Math.pow(pointC.GetY() - pointA.GetY(),2));
		System.out.println(this.sideA);
		System.out.println(this.sideB);
		System.out.println(this.sideC);

	}
	
	double GetArea()
	{
		double s = (sideA + sideB + sideC) / 2;
		return Math.sqrt(s * (s - sideA) * (s - sideB) * (s - sideC));
	}
	
	double GetPerimeter()
	{
		return sideA + sideB + sideC;
	}
	
	public static void main(String args[])throws IOException
	{

		BufferedReader aRead = new BufferedReader(new InputStreamReader(System.in));
		String pointX = "",pointY = "";
		double x = 0,y = 0;
		System.out.println("请输入三角形顶点A的坐标:");
		pointX = aRead.readLine();
		pointY = aRead.readLine();
		x = Double.parseDouble(pointX);
		y = Double.parseDouble(pointY);
		Point aPointA =  new Point(x,y);
		System.out.println("请输入三角形顶点B的坐标:");
		pointX = aRead.readLine();
		pointY = aRead.readLine();
		x = Double.parseDouble(pointX);
		y = Double.parseDouble(pointY);
		Point aPointB =  new Point(x,y);
		System.out.println("请输入三角形顶点C的坐标:");
		pointX = aRead.readLine();
		pointY = aRead.readLine();
		x = Double.parseDouble(pointX);
		y = Double.parseDouble(pointY);
		Point aPointC =  new Point(x,y);
		if((aPointA.GetY() - aPointB.GetY()) / (aPointA.GetX() - aPointB.GetX()) == (aPointC.GetY() - aPointB.GetY()) / (aPointC.GetX() - aPointB.GetX()))
		{
			System.out.println("这三点不能构成三角形!");
		}
		else
		{
			Triangle aTriangle = new Triangle(aPointA,aPointB,aPointC);
			System.out.format("三角形的周长为:%3f",aTriangle.GetPerimeter());
			System.out.println("\n");
			System.out.format("三角形的面积为:%3f",aTriangle.GetArea());
		}
	
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -