43 lines
1.1 KiB
Java
43 lines
1.1 KiB
Java
package labMaxMin;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
import java.io.IOException;
|
|
|
|
public class Assignment {
|
|
public static int[] getMaxAndMin(int[] sequence) {
|
|
int min = sequence[0];
|
|
int max = sequence[0];
|
|
for (int num : sequence) {
|
|
if (num < min) min = num;
|
|
if (num > max) max = num;
|
|
}
|
|
return new int[] { max, min };
|
|
}
|
|
|
|
public static void run(String input_path) {
|
|
int[] sequence;
|
|
int arraySize = 1;
|
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader(input_path))) {
|
|
// Get the size of the sequence
|
|
arraySize = Integer.parseInt(br.readLine());
|
|
sequence = new int[arraySize];
|
|
|
|
// Read the sequence
|
|
for (int i = 0; i < arraySize; i++) {
|
|
sequence[i] = Integer.parseInt(br.readLine());
|
|
}
|
|
|
|
// Get max and min values
|
|
int[] maxAndMin = getMaxAndMin(sequence);
|
|
|
|
// Output
|
|
System.out.println(maxAndMin[0] + ";" + maxAndMin[1]);
|
|
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|