Input seems correct. First I had 2 if-statements in the for-loop with correct output.
Changed it to an if and an else if-statement. Still not passing the test.
Changed it to 2 seperate for-loop with if-statements. Still not passing the test.
What am I doing wrong?
package com.codegym.task.task07.task0721;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
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 = 0;
int minimum = 0;
//write your code here
int [] numbers = new int[20];
for(int i = 0; i < 20; i++)
{
int x = Integer.parseInt(reader.readLine());//int x = Integer.parseInt(reader.readLine());//reads input from keyboard 20 times
numbers[i] = x; // adds the read number into array
// System.out.print(numbers[i] + " ");//to check if it works and it does
}
for( int j= 0; j < 20; j++)// loop over the array
{
if(numbers[j] > maximum)
{//compare each one with the maximum
maximum = numbers[j];
}
}
for( int k= 0; k < 20; k++)//loop over the array
{
if(numbers[k] < minimum)//compare each one with the minimum
{
minimum = numbers[k];
}
}
System.out.print(maximum + " " + minimum);
}
}