Created
March 19, 2017 12:03
-
-
Save fermopili/16983f4a8417bce2eae4409cbbadb63e to your computer and use it in GitHub Desktop.
com.javarush.task.task11.task1123
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task11.task1123; | |
/* | |
Написать метод, который возвращает минимальное и максимальное числа в массиве. | |
*/ | |
public class Solution { | |
public static void main(String[] args) throws Exception { | |
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5}; | |
Pair<Integer, Integer> result = getMinimumAndMaximum(data); | |
System.out.println("Minimum is " + result.x); | |
System.out.println("Maximum is " + result.y); | |
} | |
public static Pair<Integer, Integer> getMinimumAndMaximum(int[] array) { | |
if (array == null || array.length == 0) { | |
return new Pair<Integer, Integer>(null, null); | |
} | |
int min=array[0]; | |
int max=array[0]; | |
for(int i=1;i<array.length;i++) | |
{ | |
if(min>array[i]) | |
min=array[i]; | |
if(max<array[i]) | |
max=array[i]; | |
} | |
//Напишите тут ваше решение | |
return new Pair<Integer, Integer>(min, max); | |
} | |
public static class Pair<X, Y> { | |
public X x; | |
public Y y; | |
public Pair(X x, Y y) { | |
this.x = x; | |
this.y = y; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment