The question was solved but there is one issue I would like to ask.
For public static List<Integer> getIntegerList() throws IOException {,
I created an list with the name list.
but then for public static int getMinimum(List<Integer> array) {
I tried to write for (int i=0;i<list.size();i++) but end up this is error.
Why instead (int i=0;i<array.size();i++) is the correct answer?
Since when the list name changed from list to array? I guess there is sth I misunderstood...thanks.
package com.codegym.task.task08.task0822;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/*
Minimum of N numbers
*/
public class Solution {
public static void main(String[] args) throws Exception {
List<Integer> integerList = getIntegerList();
System.out.println(getMinimum(integerList));
}
public static int getMinimum(List<Integer> array) {
// Find the minimum here
int minimum = Integer.MAX_VALUE;
for (int i=0;i<array.size();i++) {
if (array.get(i)<minimum)
minimum = array.get(i);
}
return minimum;
}
public static List<Integer> getIntegerList() throws IOException {
// Create and initialize a list here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
List<Integer> list = new ArrayList<>();
int n = Integer.parseInt(br.readLine());
for (int i=0;i<n;i++) {
int a = Integer.parseInt(br.readLine());
list.add(a);
}
return list;
}
}