public class Kumite { public static String highAndLow(String numbers) { String[] integerStrings = numbers.split(" "); int maxValue = Integer.parseInt(integerStrings[0]); int minValue = Integer.parseInt(integerStrings[0]); for (int i = 1; i < integerStrings.length; i++){ int number = Integer.parseInt(integerStrings[i]); if(number > maxValue){ maxValue = number; } if(number < minValue){ minValue = number; } } return Integer.toString(maxValue) + " " + Integer.toString(minValue); } }
public class ns {public static String highAndLow(String numbers) {String[] integerStrings = numbers.split(" ");int[] integers = new int[integerStrings.length];for (int i = 0; i < integers.length; i++){integers[i] = Integer.parseInt(integerStrings[i]);}int maxValue = integers[0];for(int y=1;y < integers.length;y++){if(integers[y] > maxValue){maxValue = integers[y];}}int minValue = integers[0];for(int q=1;q<integers.length;q++){if(integers[q] < minValue){minValue = integers[q];}}String s = Integer.toString(maxValue);String m = Integer.toString(minValue);String r = s + " " + m;return r;- public class Kumite {
- public static String highAndLow(String numbers) {
- String[] integerStrings = numbers.split(" ");
- int maxValue = Integer.parseInt(integerStrings[0]);
- int minValue = Integer.parseInt(integerStrings[0]);
- for (int i = 1; i < integerStrings.length; i++){
- int number = Integer.parseInt(integerStrings[i]);
- if(number > maxValue){
- maxValue = number;
- }
- if(number < minValue){
- minValue = number;
- }
- }
- return Integer.toString(maxValue) + " " + Integer.toString(minValue);
- }
- }
public static void main(String args[]) {System.out.println(highAndLow("13 48 19 20 24 12"));}}
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; // TODO: Replace examples and use TDD development by writing your own tests public class SolutionTest { @Test public void testSomething() { assertEquals("9 1", Kumite.highAndLow("1 4 2 6 1 6 1 5 2 8 9")); assertEquals("9 -10", Kumite.highAndLow("1 4 2 6 -10 6 1 5 2 8 9")); } }
- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
- // TODO: Replace examples and use TDD development by writing your own tests
- public class SolutionTest {
- @Test
- public void testSomething() {
- assertEquals("9 1", Kumite.highAndLow("1 4 2 6 1 6 1 5 2 8 9"));
- assertEquals("9 -10", Kumite.highAndLow("1 4 2 6 -10 6 1 5 2 8 9"));
- }
- }