张福海
张福海
电子与信息工程学院课后作业
班级 二 学号 2362720049 姓名张福海
Write a program that prompts the user to enter the x- and y-coordinates of the three
corner points in a triangle and then displays the triangle’s angles.
Analysis:
(Describe the problem including input and output in your own words.)
The program you provided prompts the user to enter the x- and y-coordinates of three
corner points of a triangle. After receiving the input, it calculates the three sides of the
triangle using the distance formula and then calculates the three angles of the triangle
using trigonometric formulas.
Input: The user needs to input six values: x and y coordinates of each of the three
points.
Output: The program displays the measures of the three angles of the triangle formed
by the given points.
Design:
(Describe the major steps for solving the problem.)
● The user is prompted to enter the x- and y-coordinates of the three points that form
the corners of the triangle.
● The program then computes the lengths of the three sides of the triangle using the
distance formula.
● Using the lengths of the sides, the program calculates the measures of the three
angles of the triangle using trigonometric functions.
● Finally, it displays the calculated angles.
Coding: (Copy and Paste Source Code here. Format your code using Courier
10pts)
import java.util.Scanner;
//Display results
System.out.println("The three angles are " +
Math.round(A * 100) / 100.0 + " " +
Math.round(B * 100) / 100.0 + " " +
Math.round(C * 100) / 100.0);
}
}