Java Program to find Angle of a Triangle

Write a Java Program to find Angle of a Triangle with an example. This Java example allows entering the remaining two angles of a triangle. As we all know, the sum of three angles in a triangle equals 180. So, subtracting the given two angles from 180 gives the third angle of a triangle.

package Area;

import java.util.Scanner;

public class AngleOfTriangle1 {
	private static Scanner sc;

	public static void main(String[] args) {
		int ang1, ang2, ang3; 
		sc = new Scanner(System.in);
		
		System.out.println("Enter two angles of a Triangle =  ");
		ang1 = sc.nextInt();
		ang2 = sc.nextInt();
		
		ang3 = 180 - (ang1 + ang2);

		System.out.format("The Third Angle of a Triangle = %d",ang3);
	}
}
Enter two angles of a Triangle =  
60
45
The Third Angle of a Triangle = 75

In this Java program, we declared a TriangleAngle function that returns a triangle’s remaining or third angle.

package Area;

import java.util.Scanner;

public class AngleOfTriangle2 {
	private static Scanner sc;

	public static void main(String[] args) {
		int ang1, ang2, ang3; 
		sc = new Scanner(System.in);
		
		System.out.println("Enter two angles of a Triangle =  ");
		ang1 = sc.nextInt();
		ang2 = sc.nextInt();
		
		ang3 = TriangleAngle(ang1, ang2);

		System.out.format("The Third Angle of a Triangle = %d",ang3);
	}
	
	public static int TriangleAngle(int ang1, int ang2) {
		return 180 - (ang1 + ang2);
	}
}
Java Program to find Angle of a Triangle 1

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.