LargestInteger.java 603B

1234567891011121314151617181920212223
  1. public class LargestInteger {
  2. public Integer findLargestNumberUsingConditional(Integer[] integers){
  3. int maxNum = integers[0];
  4. for(int i=1; i<integers.length;i++){
  5. int newMax = integers[i] >= integers[i-1] ? integers[i] : maxNum;
  6. maxNum=newMax;
  7. }
  8. return maxNum;
  9. }
  10. public Integer findLargestNumberUsingMathMax(Integer[] integers){
  11. int maxNum = integers[0];
  12. for(int i=1; i<integers.length;i++){
  13. int newMax = Math.max(integers[i],maxNum);
  14. maxNum=newMax;
  15. }
  16. return maxNum;
  17. }
  18. }