With this code I got an error message
Error in com/codegym/task/task07/task0721/Solution.java on line 28
variable maximum might not have been initialized
Since i starts with 0, I was assuming list[i] assign to maximum and minimum which would initialize 2 variables. But apparently it doesn't work that way. Could you please explain why?
package com.codegym.task.task07.task0721;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Min and max in arrays
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int maximum;
int minimum;
//write your code here
int[] list = new int[20];
for (int i = 0; i < list.length; i++){
list[i] = Integer.parseInt(reader.readLine());
if (i == 0){
maximum = list[i];
minimum = list[i];
}
else{
maximum = maximum < list[i] ? list[i] : maximum;
minimum = minimum > list[i] ? list[i] : minimum;
}
}
System.out.print(maximum + " " + minimum);
}
}