Ad
Code
Diff
  • 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]);
        }
    }
    • 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.
    • int max = my_array[0];
    • for (int i = 1; i < my_array.length; i++){
    • if (my_array[i] > max) max = my_array[i];
    • }
    • return max;
    • Arrays.sort(my_array);
    • return (my_array[my_array.length-1]);
    • }
    • }
Code
Diff
  • 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.
            
           int max = my_array[0];
          for (int i = 1; i < my_array.length; i++){
             if (my_array[i] > max) max = my_array[i];
            }
            return max;
        }
    }
    • 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.
    • return 7;
    • int max = my_array[0];
    • for (int i = 1; i < my_array.length; i++){
    • if (my_array[i] > max) max = my_array[i];
    • }
    • return max;
    • }
    • }