techhipbettruvabetnorabahisbahis forumutaraftarium24edueduedueduedueduedueduedusedu Java Program : Maximum Edge of A Triangle | Java Programs
Latest :

Java Program : Maximum Edge of A Triangle | Java Programs

Java program to calcuate the maximium edge of triangle, Our problem statement here is, to find the longest side or edge of a triangle. For this, our required input will be, the lengths of three sides or edges of a triangle. Our expected output is, one of these three edges that is the longest of all.

Initially, to read the three edges at runtime, we can make use of the Scanner class in Java. This class reads any input from the console screen at runtime. To make use of this class, we first create an object instantiating the class and then call the necessary method to read a primitive datatype value. Here, our edges are of integer type so, we invoke the nextInt() method as shown below:

After reading the three edges, we need to start comparing it with each other to find the largest among them.

First we see if, edge1 (e1) is greater than edge2(e2). If yes then, we check whether edge1 (e1) is greater than edge3 (e3) too and if yes then, edge1 (e1) is the longest and we store this in a variable (max). If egde1 (e1) is not greater than edge3 (e3) then, edge3 (e3) is the longest and will be stored in the variable (max).

if(e1>=e2) {

if(e1>=e3)

max=e1;

else

max=e3;

}

Now, if edge1 (e1) is not greater than edge2 (e2) then, we check whether edge2 (e2) is greater than edge3 (e3). If yes then, edge2 (e2) is the longest and is stored in the max variable and else, edge3 (e3) is the greatest and is stored in the max variable.

else if(e2>=e3) {

max=e2;

}

else

max=e3;

Our desired output i.e., the longest edge among the three is stored in this max variable and can be displayed on the console screen by making use of System.out.println() method.

System.out.println(“The maximum edge of a trinagle of 3 edges (“+e1+” “+e2+” “+e3+”) is :”+max);

Output:

Here, e1=4, e2=3 and e3=5,

e1>=e2 i.e., 4>=3 yes so,

e1>=e3 i.e., 4>=5 no so, max=e3=5.

Static Method – Edge of Triangle Java

This method also has the exact same logic and set of statements as discussed above but the difference is that, the main logic with comparison of three edges is placed within a separate static method (findMaxEdge) which takes three edges as arguments and returns the longest edge (m) to the main function.

We do this so that, we can make this part of the code reusable. If the same logic were to be used elsewhere in the code later then, instead of rewriting the same set of statements we can just make a method call and pass the arguments.

Not just that, it also enhances the readability of the code and makes it clearer. Also, for a static method, we do not need to create an object despite being outside main method. This is because, static method belongs to the class and not the instance.

Output:

s1=20, s2=20 and s3=20.

s1>=s2 i.e., 20>=20 yes so,

s1>=s3 i.e., 20>=20 yes then, m=e1=20.

 

Check : Transpose Matrix In Java

techhipbettruvabetnorabahisbahis forumutaraftarium24edueduedueduseduedusedusedueduedus
x

Check Also

Rhombus Star Pattern Program In Java – Patterns

Java program to print Rhombus star pattern program. We have written the below print/draw Rhombus ...

betwoonhacklink satın aljojobet girişakcebet uyeliksupertotobet1xbet girişmelbet girişbetwinnerpinup uyelikbtcbahis girişmostbet girişbetwinner girişxslotskyloft uyelikmegapari uyeliktipobetgrandpashabetgrandpashabetmariobett.mebetandreasenbetcasivalmisbahismyhitbetonbahistipobetbahsinevavepasgolgrandpashabetmarsbahispusulabetcasibomcasibom girişcasibom güncel girişcasibomcasibom girişdeneme bonusu veren sitelerhttps://mobilebarhawaii.com/ballettea tropazjokerbet güncel girişmatadorbetbets10betturkeycasibomkingroyalbets10 girişbets10bets10 girişmaldives casinohacklinkgrandpashabetbetmatik girişmelbetmostbetmegapari üyelikmatadorbetartemisbetJojobet girişcasibompinco girisonwinonwin girişcasibom güncel girişselcuksportshdcasibomcasibomatakoy escortatakoy escortsisli escortgalatabahisliste paris sportifjeux casino gratuit avec bonusSimsinos CasinojojobetCashimashi AvisWunderWinsparier sur les cornersGamdomCasibommadridbet girişmatbetpinbahisemiratesbettrbetcasibomcratosroyalbetcasinokaliprensbetmostbet guncel girisbetandyou guncel girisromabet guncel giris7slots guncel girisbizbet guncel girisrocksroyalbetkazandradeneme bonusu veren sitelergrandpashabetonwinprincessbetbetkanyonpinup yeni girismatadorbet yeni girisroketbet yeni girisskyloft yeni girismegapari yeni girissavoybettingcasinomhubligobetmavibetenobahisJojobetjetbetcasinomaxikingroyalsahabethttps://www.escortbayanlariz.net/beylikdüzü escortfikstürbetmisliwinbetwoonjojobetsahabettarafbetpusulabetcoinbarmariobetmilanobetlunabetcasibomcasibom girişbetsmovebetnanobetparkvevobahisKonak escortimajbetbetnanovevobahismarsbahismarsbahisbetebetcasibombetciobakırköy escortcasinometropolmatbetsüperbetin güncel girişjojobetpusulabetholiganbetmarsbahisjojobet girişcasibomextrabetcasibomdeneme bonusu veren sitelerholiganbetmatbetbetturkeyhalkali escortbetwooncasibom güncel girişsahabetartemisbetbetparkmavibetjojobetbets10dumanbetdumanbetfixbetkralbetkulisbetsekabet girişholiganbet güncel girişjojobet güncel girişartemisbetimajbetcasibom girişjojobetpadişahbetbets10 girişbets10 girişonwinselçuksportsSekabetholiganbethttps://www.gvscolombia.com/casino sitelerimatbet güncel girişartemisbetimajbet giriş1xbet1xbetcasibomgrandpashabetredwincasibomankara escort bayanxslotcasibomgrandpashabetcasivalmarsbahispusulabetbetofficeJojobet girişmaldives betcasibom girişCasibommarsbahiscasibom girişgrandpashabet girişbahiscasinojokerbet güncel girişcasibomcasibom girişcasibomcasibomtaraftarium24holiganbetholiganbetholiganbetjojobetcasibomGrandpashabet güncel girişcasibomjojobetonwinextrabetbetwoonextrabet girişmatbetbetciomarsbahisgrandpashabetTipobetbetistPusulabetcasibomesenyurt anal escortbetcioSekabetcasibomvevobahisbetturkeycasino sitelerigrandpashabetİstanbul Escortcasinomaxihttps://www.gvscolombia.com/betebetgrandpashabetdeneme bonusu veren sitelerfixbetholiganbetmarsbahis girişstarzbetjojobetjojobet girişmrbahismrbahisCasibom girişsahabetjojobetjojobet girişİmajbetcasibomkucukcekmece escortmarsbahissahabetsekabetrestbetpinbahisonwinmobilbahismeritbetmavibetmatbetmatadorbetmaltcasinobets10meritkingizmir escorttexas sweepstakesflorida sweepstakessweepstakes sportsbooksweepslotscasibomcasibom girişbankobet girişGrandpashabetmobilbahisbetciorestbetcasibomgrandpashabetmatadorbetmaltcasinoholiganbetmarsbahisonwinsahabetsekabetmatbetimajbetmarsbahis güncel girişbetsattuzla escort bayancanlı bahisimajbetstarzbetmobil ödeme bozdurmajojobetcasibombetcioCASİBOMcasibomcasibom girişcasibom güncel girişjojobetcasibomcasibom girişevde paketleme işicasibom giriştempobetkalebetsafirbetngsbahispusulabetcoinbartarafbettempobetmarsbahisperabetstarzbetpusulabet