package com.codegym.task.task10.task1020;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] array = new int[30];
for (int i = 0; i < 30; i++) {
array[i] = Integer.parseInt(reader.readLine());
}
sort(array);
System.out.println(array[9]);
System.out.println(array[10]);
}
public static void sort(int[] array) {
for (int i = 1 ; i < array.length ; i++){
int indexOfMin = i;
for (int j = i + 1 ; j < array.length ; j++){
if (array[indexOfMin] > array[j]){
indexOfMin = j;
}
}
int temp = array[indexOfMin];
array[indexOfMin] = array[i];
array[i] = temp;
}
}
}
Wanna help
Resolved
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Sergio
8 May 2019, 11:10solution
See the line 26. The initial value for i must be 0, and last index to check is:
+4