import java.util.Scanner;
import java.text.DecimalFormat;
public class RightTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.000");
double side_A, side_B, angle_A, angle_B, hypotenuse;
final double right_Angle = 90.0;
System.out.print("Please enter length of side a: ");
side_A = input.nextDouble();
System.out.print("Please enter length of side b: ");
side_B = input.nextDouble();
System.out.printf("Side A = %6s\n",df.format(side_A));
System.out.printf("Side B = %6s\n",df.format(side_B));
hypotenuse = Math.sqrt(side_A*side_A+side_B*side_B);
angle_A = Math.asin(side_B/hypotenuse)*180/Math.PI;
angle_B = right_Angle-angle_A;
System.out.printf("Hypotenuse = %6s\n",df.format(hypotenuse));
System.out.printf("Angle A = %6s\n",df.format(angle_A));
System.out.printf("Angle B = %6s\n",df.format(angle_B));
System.out.printf("Angle C = %6s\n",df.format(right_Angle));
}
}
This is what i have so far, now i just need the area and perimeter. stuck at this point.
--- Update ---
I was able to figure it out here is my final result:
import java.util.Scanner;
import java.text.DecimalFormat;
public class RightTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.000");
double side_A, side_B, angle_A, angle_B, hypotenuse, triangle_Area, triangle_Perimeter;
final double right_Angle = 90.0;
System.out.print("Please enter length of side a: ");
side_A = input.nextDouble();
System.out.print("Please enter length of side b: ");
side_B = input.nextDouble();
System.out.printf("Side a = %6s\n",df.format(side_A));
System.out.printf("Side b = %6s\n",df.format(side_B));
hypotenuse = Math.sqrt(side_A*side_A+side_B*side_B);
angle_A = Math.asin(side_B/hypotenuse)*180/Math.PI;
angle_B = right_Angle-angle_A;
System.out.printf("Hypotenuse = %6s\n",df.format(hypotenuse));
System.out.printf("Angle A = %6s\n",df.format(angle_A));
System.out.printf("Angle B = %6s\n",df.format(angle_B));
System.out.printf("Angle C = %6s\n",df.format(right_Angle));
triangle_Area = side_A*side_B/2;
System.out.printf("Area = %6s\n",df.format(triangle_Area));
triangle_Perimeter = side_A+side_B+Math.sqrt(side_A*side_A+side_B*side_B);
System.out.printf("Perimeter = %6s\n",df.format(triangle_Perimeter));
input.close();
}
}