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.
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;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Write more tests to prove your code bleow class SolutionTest { @Test void testSomething() { assertEquals(Kata.findMax(new int[]{4, 5, 6, 7}), 7); assertEquals(Kata.findMax(new int[]{24, 4, 50, 12}), 50); assertEquals(Kata.findMax(new int[]{2, 8, 64, 4, 16, 32}), 64); assertEquals(Kata.findMax(new int[]{-5, -24, -8, -8}), -5); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Write more tests to prove your code bleow
- class SolutionTest {
- @Test
- void testSomething() {
- assertEquals(Kata.findMax(new int[]{4, 5, 6, 7}), 7);
- assertEquals(Kata.findMax(new int[]{24, 4, 50, 12}), 50);
- assertEquals(Kata.findMax(new int[]{2, 8, 64, 4, 16, 32}), 64);
- assertEquals(Kata.findMax(new int[]{-5, -24, -8, -8}), -5);
- }
- }