Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)
Find Missing Third Angle in Triangle : Java Program
Latest :

Find Missing Third Angle in Triangle : Java Program

Java Program to enter two angles of a triangle and find the third angle in Java, to find the missing third angle, we first need the other two known angles of the triangle. Our expected output is whether the angle is an acute angle, an obtuse angle or a right angle.

To begin the solution, we first require the two angles (a1 and a2). Their values keep varying based on our use case so, we have to read these inputs at runtime. To do so, we can make use of the Scanner class as it can be used to read input of any primitive datatype from the console screen at runtime by the user.

To use this class, we need to first create an object instantiating it and followed by which we invoke our necessary method on the basis of our input type. Here, the two angles of the triangle are of integer type so, we invoke the nextInt() method by using the object created earlier.

Now we have all the necessary inputs, so proceed with further steps of execution. We make a method call for a static method (missingangle) and pass both the input angles (x,y) as arguments of this method.

For knowledge, the sum of all the three angles of a triangle is always 180 degrees. In this static method (missingangle) we first check whether the sum of the two know angles is lesser than or greater than or equal to 90 degrees.

Angle less than 90 degrees is called acute angle, angle greater than 90 degrees is called obtuse angle and angle equal to 90 degrees is called right angle.

If the sum of known angles i.e., x+y is greater than 90 degrees then,

x+y>90 and x+y+missingangle=180 so, missing angle < 90 which means it is an acute angle.

Else, if the sum of known angles is equal to 90 degrees then,

x+y=90 and x+y+missing angle=180 so, missing angle = 90 which means it’s a right angle.

Else, if the sum of known angles is lesser than 90 degrees then,

x+y<90 and x+y+missingangle=180 so, missing angle>90 hence, it’s an obtuse angle.

Using these conditions, we store which type of angle it is in a string variable (str) and return this variable to the main method. This is our resultant output which can then, be displayed on the console screen.

String str=” “;

if(x+y>90)

str=”Acute angle”;

if(x+y==90)

str=”Right angle”;

if(x+y<90)

str=”Obtuse angle”;

return str;

Output:

Angle of A Triangle in Java – Type 2

In this type as well, we make use of the same logic and set of statements as discussed above. The difference is that, in the above type we made use of a static method consisting of the main logic whereas here, we place the entire code in the main method itself.

We make use of static method earlier to make the logic part of code reusable. Instead of rewriting the same statements when in need elsewhere, we can just make a method call.

Apart from that, for a static method, we do no need to create an object instantiating the class too because, static method belongs to the class and not the instance. If we are sure of that, we do not need to reuse this elsewhere in the future we can write the entire code within the main method itself as below.

Output:

x

Check Also

Contact us

For Any Guest Posts Related or for Further Enquires, Drop an email at : nani.marri219@gmail.com

atakoy escortatakoy escortbakırköy escorthalkali escortbağcılar escortsightcaredeneme bonusu veren siteleristanbul, escortromabetdeneme bonusu veren sitelerdeneme bonusu veren sitelerbetpuan güncelDeneme Bonusu Veren Sitelergrandpashabetdeneme bonusu veren sitelergrandpashabetgrandpashabetgrandpashabetcasino siteleriDeneme Bonusu Veren SitelerAlanya EscortDeneme Bonusu Veren Sitelervaycasinograndpashabetjustin tvgrandpashabetgrandpashabetgrandpashabetGrandpashabetgrandpashabetgrandpashabetGrandpashabetpadişahbetpadişahbet girişjojobetcasibom girişvaycasinoHitbetjojobetjojobetmatbetsahabetgalabet güncel girişdeneme bonusu veren sitelerdeneme bonusu veren sitelerİstanbul Escortbahiscomiptv satın almavibetextrabetbets10starzbetholiganbetcasibomMarsbahisHoliganbetslotbar girişsamsun escortcasibomcasibom girişcasibomcasibom girişcasibomjojobet girişHoliganbet girişBetturkeyBetturkey GirişBetcioBetcio GirişKralbetKralbet Girişcasibom girişcasibomalanya escortKingroyalKingroyal Girişmeritkingcasibom girişbetgaranti güncel girişcasibomescort antalyabahcesehir masaj salonucasibom girişcasibomcasibom girişmariobet girişcasibomcasibom güncel girişjojobetmarsbahismarsbahis giriştimebetgrandbettinggrandbettingtimebet giriştaraftarium24holiganbetholiganbetlidyabet girişcasibombets10takım2pusulabetpusulabet girişextrabet girişextrabetsekabetsekabet girişsekabet girişlunabet1xbetholiganbet girişsekabet girişmatadorbetmatadorbetmeritkingmavibetholiganbetmatadorbet girişcasibom güncel girişmatadorbet girişasyabahis girişpusulabet girişGrandpashabetGrandpashabet girişGRANDPASHABETroyalbetcasinofastPalacebetramadabetgrandpashabetgrandpashabetcasibom güncel girişcasibomgrandpashabetjojobet