Ad
Arrays
Fundamentals

In this Kata your job is to find the biggest Integer in an Array and return it as such.

'1,2,3,4' -> '4'

The Integers passed can be non-negativ but will always be valid numbers.

Code
Diff
  • import java.util.*;
    
    public class Kata {
        public static int findMax(int[] my_array) {
          
          int max = my_array[0];
          
          for(int i : my_array) {
            if(i > max) max = i;
          }
          
          return max;
        }
    }
    • import java.util.*;
    • public class Kata {
    • public static int findMax(int[] my_array) {
    • // Write a method that returns the largest integer in the list.
    • // You can assume that the list has at least one element.
    • Arrays.sort(my_array);
    • return (my_array[my_array.length-1]);
    • int max = my_array[0];
    • for(int i : my_array) {
    • if(i > max) max = i;
    • }
    • return max;
    • }
    • }