Ad

You type a string of a list of numbers, and this method returns the highest int and the lowest int in the string.

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 static void main(String args[]) {
		
		System.out.println(highAndLow("13 48 19 20 24 12"));
		
	}
	
}