LargestInteger.java 860B

1234567891011121314151617181920212223242526272829303132
  1. public class LargestInteger {
  2. private Integer maxValue;
  3. private Integer currentValue;
  4. private Integer nextValue;
  5. public Integer findLargestNumberUsingConditional(Integer[] integers){
  6. maxValue = 0;
  7. currentValue = 0;
  8. nextValue =0;
  9. for (int i = 0; i < integers.length; i++) {
  10. currentValue = integers[i];
  11. if(currentValue > maxValue)
  12. maxValue = currentValue;
  13. }
  14. return maxValue;
  15. }
  16. public Integer findLargestNumberUsingMathMax(Integer[] integers){
  17. maxValue = 0;
  18. currentValue = 0;
  19. nextValue =0;
  20. for (int i = 0; i < integers.length-1; i++) {
  21. currentValue = integers[i];
  22. nextValue = integers[i + 1];
  23. maxValue = Math.max(currentValue, nextValue);
  24. }
  25. return maxValue;
  26. }
  27. }