-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx5.java
More file actions
29 lines (24 loc) · 790 Bytes
/
Ex5.java
File metadata and controls
29 lines (24 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package java_exercises_1_sda;
//Dla zadanej tablicy intów wyświetl najmniejszą oraz największą liczbę z tablicy
public class Ex5 {
public static void main(String[] args) {
int[] numbers = {99, -1, 0, 2};
getMinAndMaxValueFromArray(numbers);
}
public static void getMinAndMaxValueFromArray(int[] numbers) {
if (numbers.length > 0) {
int min = numbers[0];
int max = numbers[0];
for (int number : numbers) {
if (number > max) {
max = number;
}
if (number < min) {
min = number;
}
}
System.out.println("Min: " + min);
System.out.println("Max: " + max);
}
}
}