Ad
Code
Diff
  • public class ns {
        public static String highAndLow(String numbers) {
            String[] integerStrings = numbers.split(" ");
            int maxValue = Integer.MIN_VALUE;
            int minValue = Integer.MAX_VALUE;
    
            for (String num : integerStrings) {
                int n = Integer.parseInt(num);
                if (n > maxValue) maxValue = n;
                if (n < minValue) minValue = n;
            }
    
            return maxValue + " " + minValue;
        }
    
        public static void main(String[] args) {
            System.out.println(highAndLow("13 48 19 20 24 12"));  // Output: 48 12
        }
    }
    • public class ns {
    • public static String highAndLow(String numbers) {
    • String[] integerStrings = numbers.split(" ");
    • public static String highAndLow(String numbers) {
    • String[] integerStrings = numbers.split(" ");
    • int maxValue = Integer.MIN_VALUE;
    • int minValue = Integer.MAX_VALUE;
    • int[] integers = new int[integerStrings.length];
    • for (String num : integerStrings) {
    • int n = Integer.parseInt(num);
    • if (n > maxValue) maxValue = n;
    • if (n < minValue) minValue = n;
    • }
    • 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];
    • }
    • }
    • return maxValue + " " + minValue;
    • }
    • 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"));
    • }
    • public static void main(String[] args) {
    • System.out.println(highAndLow("13 48 19 20 24 12")); // Output: 48 12
    • }
    • }