java - Get Largest Number from a list of numbers -
public void getjustrevisionsnumberdata(string duanum) { list<number> dua = new arraylist<number>(); dua = getrevisionsnum(duanum); // dua object -> 123, 843, 455, 565 // want 843 for(number number : dua) { system.out.println(number); } }
getrevisionsnum
public list<number> getrevisionsnum(string duanum) { session session = factory.opensession(); auditreader auditreader = auditreaderfactory.get(session); return auditreader.getrevisions(duavo.class, duanum);
i'm trying largest number unable come solution. suggestions?
you can keep track of largest number you've come across far in variable largestnumber
, , once you've iterated through whole set, can print out system.out.println(largestnumber)
outside of loop.
double largestnumber = double.min_value; for(number number: dua) { if(number.doublevalue() > largestnumber) largestnumber = number; } system.out.println(largestnumber);
setting largestnumber
double.min_value
ensures if you're dealing large negative numbers, should still satisfy number.doublevalue() > largestnumber
. calling .doublevalue()
in comparison necessary you'll have 2 double
s compare.
Comments
Post a Comment