The getIntegerList() method should read the number N from the keyboard and then return a list of N elements, which has been filled with numbers read from the keyboard.
My program is reading method:
int N = Integer.parseInt(bf.readLine());
and returns a list of N elements below:
for (int i = 0; i<listaLiczbCalkowitych.get(0); i++) {
listaLiczbCalkowitych.add(Integer.parseInt(bf.readLine()));}
return listaLiczbCalkowitych;
Where do I make mistake?
package pl.codegym.task.task08.task0822;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/*
Najmniejsza z N liczb
*/
public class Solution {
public static void main(String[] args) throws Exception {
List<Integer> listaLiczbCalkowitych = getListaLiczbCalkowitych();
System.out.println(getMinimum(listaLiczbCalkowitych));
}
public static int getMinimum(List<Integer> array) {
int min = array.get(0);
for (int i = 1; i< array.size(); i++) {
if (min > array.get(i))
min = array.get(i);
}
return min;
}
// Second method can be: Collections.min(array);
public static List<Integer> getListaLiczbCalkowitych() throws IOException {
ArrayList<Integer> listaLiczbCalkowitych = new ArrayList<Integer>();
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(bf.readLine());
listaLiczbCalkowitych.add(N);
for (int i = 0; i<listaLiczbCalkowitych.get(0); i++) {
listaLiczbCalkowitych.add(Integer.parseInt(bf.readLine()));}
return listaLiczbCalkowitych;
}
}
/*Najmniejsza z N liczb
1. Używając klawiatury, wprowadź liczbę N.
2. Wczytaj N liczb całkowitych i umieść je w liście: metoda getListLiczbCalkowitych.
3. Znajdź minimum pośród elementów listy: metoda getMinimum.
Requirements:
1. Program powinien wyświetlać tekst na ekranie.
2. Program powinien czytać wartości z klawiatury.
3. Klasa Solution musi mieć tylko trzy metody.
4. Metoda getListaLiczbCalkowitych() powinna czytać liczbę N z klawiatury i zwracać listę złożoną z N elementów, zapełnioną liczbami czytanymi z klawiatury.
5. Metoda getMinimum() powinna zwracać minimum pośród elementów listy.
6. Metoda main() powinna wywoływać metodę getListaLiczbCalkowitych().
7. Metoda main() powinna wywoływać metodę getMinimum().*/