https://www.codewars.com/kata/highest-and-lowest/train/java
Instructions
In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.
Example:
highAndLow("1 2 3 4 5") // return "5 1"
highAndLow("1 2 -3 4 5") // return "5 -3"
highAndLow("1 9 3 4 -5") // return "9 -5"
Solution
public class Kata {
public static String highAndLow(String numbers) {
String[] array = numbers.split(" ");
String big = array[0];
String small = array[0];
for(int i=0; i<array.length; i++)
{
if(Integer.parseInt(big) <= Integer.parseInt(array[i]))
{
big = array[i];
}
else if(Integer.parseInt(small) >= Integer.parseInt(array[i]))
{
small = array[i];
}
}
return (big +" "+ small);
}
}