package com.codegym.task.task07.task0721;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/*
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 [] table = new int[20];
int min = table[0];
int max= table[0];
Scanner scann = new Scanner(System.in);
for(int i=0; i<20; i++)
{
table[i] = scann.nextInt();
}
for(int i =0; i<20; i++)
{
if(table[i] < min)
{
min = table[i];
}
if(table[i] > max)
{
max = table[i];
}
}
int maximum = max;
int minimum = min;
//write your code here
System.out.print(maximum + " " + minimum);
}
}
Why is not OK?
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Marek Pasierbek Working at Nexus Polska
10 July 2020, 13:58
so any idea?
0
Angel Li
13 July 2020, 17:16
1. I found an error with your logic in line 26 and line 30 (the if statements) because since you set the min and max to table[0], when comparing table[0] to table [i] and i is equal to 0, you're comparing the same thing. So I think it should be >= and <=, but I'm not sure if it would make a difference.
2. When you are adding the numbers to your array, you are adding Strings, so maybe change line 21 to include Integer.parseInt()?
Other than the two points above, your code is exactly like mine (although I used BufferedReader), so it should verify.
0
null
10 July 2020, 12:50
代码没有错误 可能是输出的格式不合要求
0
Angel Li
13 July 2020, 17:07
Let me translate the above message: The code doesn't have any errors. It's probably the output's format doesn't meet the requirements.
0
Marek Pasierbek Working at Nexus Polska
14 July 2020, 05:07
Yes, some days ago I did this task. Thank You for help. Sometimes we need to break and back to exercises.
0