Maybe someone can point out the flaw in my code that is giving me this error.
I appreciate any help, 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
1. Use the keyboard to enter the number N.
2. Read N integers and put them in a list: the getIntegerList method.
3. Find the minimum among the list items: the getMinimum method.
*/
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 = 0;
for (int i = 0, j = i+1; i < array.size() -1; i++) {
if (array.get(i) > array.get(j)) {
minimum = array.get(j);
}
if (array.get(i) < array.get(j)) {
minimum = array.get(i);
}
if (array.get(i) == array.get(j)) {
minimum = array.get(j);
}
}
return minimum;
}
public static List<Integer> getIntegerList() throws IOException {
// Create and initialize a list here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
List<Integer> newList = new ArrayList<>();
for (int i = 0; i < N; i++) {
newList.add(Integer.parseInt(reader.readLine()));
}
return newList;
}
}