LargestInteger.java 779B

12345678910111213141516171819202122232425262728293031
  1. import java.lang.Math;
  2. public class LargestInteger {
  3. public Integer findLargestNumberUsingConditional(Integer[] integers){
  4. for(int i = 0;i <= 2 ;i++)
  5. {
  6. if(integers[i] > integers [i+1] && integers[i] > integers[i+2])
  7. {
  8. return integers[i];
  9. }
  10. else if(integers[i+1] > integers[i] && integers[i+1] > integers[i+2])
  11. {
  12. return integers[i+1];
  13. }
  14. else
  15. {
  16. return integers[i+2];
  17. }
  18. }
  19. return 0;
  20. }
  21. public Integer findLargestNumberUsingMathMax(Integer[] integers){
  22. int max = Math.max(integers[0],integers[1]);
  23. int max1 = Math.max(max,integers[2]);
  24. return max1;
  25. }
  26. }