Write a static method named anglePairs that accepts three angles (integers), mea
ID: 3566993 • Letter: W
Question
Write a static method named anglePairs that accepts three angles (integers), measured in degrees, as parameters and returns whether or not there exists both complementary and supplementary angles amongst the three angles passed. Two angles arecomplementary if their sum is exactly 90 degrees; two angles are supplementary if their sum is exactly 180 degrees. Therefore, the method should return true if any two of the three angles add up to 90 degrees and also any two of the three angles add up to 180 degrees; otherwise the method should return false. You may assume that each angle passed is non-negative.
Explanation / Answer
//The method anglePairs checks whether or not the given three angles
//are either complementary or supplementary angles. If so then
//returns true otherwise returns false.
public static boolean anglePairs(int angleA,int angleB,int angleC)
{
//checking for complementary angles of all possible combinatioins
if(angleA+angleB==90 ||angleA+angleC==90 || angleB+angleC==90)
return true;
//checking for supplementary angles of all possible combinatioins
else if(angleA+angleB==180 ||angleA+angleC==180 || angleB+angleC==180)
return true;
else
//otherwise returns false
return false;
}
--------------------------------------------------------------------------------------------------------------
//Tester java program
//The java program test the method anglePairs whether the given three
//angles are complementary or supplementary angles.
//Triangle.java
//Compile :javac Triangle.java
//Run : java Triangle
public class Triangle
{
public static void main(String[] args)
{
int A=45;
int B=45;
int C=90;
System.out.println("A :"+A);
System.out.println("B :"+B);
System.out.println("C :"+C);
boolean isComplementary=anglePairs(A, B, C);
if(isComplementary)
System.out.println("Any two angles are complementary or supplementary");
else
System.out.println("No complementary or supplementary angles are found");
int angleA=90;
int angleB=45;
int angleC=90;
System.out.println("A :"+angleA);
System.out.println("B :"+angleB);
System.out.println("C :"+angleC);
boolean isSupplementary=anglePairs(angleA,angleB,angleC);
if(isSupplementary)
System.out.println("Any two angles are complementary or supplementary");
else
System.out.println("No complementary or supplementary angles are found");
}
//The method anglePairs checks whether or not the given three angles
//are either complementary or supplementary angles. If so then
//returns true otherwise returns false.
public static boolean anglePairs(int angleA,int angleB,int angleC)
{
//checking for complementary angles of all possible combinatioins
if(angleA+angleB==90 ||angleA+angleC==90 || angleB+angleC==90)
return true;
//checking for supplementary angles of all possible combinatioins
else if(angleA+angleB==180 ||angleA+angleC==180 || angleB+angleC==180)
return true;
else
//otherwise returns false
return false;
}
}
------------------------------------------------------------------------------------------------------------
Sample Output:
A :45
B :45
C :90
Any two angles are complementary or supplementary
A :90
B :45
C :90
Any two angles are complementary or supplementary
Hope this would be helpful
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.