package com.codegym.task.task05.task0532;
import java.io.*;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// int maximum = ;
//write your code here
// System.out.println(maximum);
String m= reader.readLine();
int n =Integer.parseInt(m) ;
int maximum=0;
if (n<=0)return;
else
for (int i= 0;i<n;i++){
String num=reader.readLine();
int ans=Integer.parseInt(num);
if(maximum<=ans) maximum=ans ;
}
System.out.println(maximum);
}
}
I can't solve the fifth requirement....some help plz
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Seb
29 December 2019, 20:50
The problem is that you set the maximum equal to 0.
Your result would be 0, if all the input numbers were less than 0 - thus the result would not be correct.
Try to initialize the value of the variable maximum with the first number that you read in. I would suggest doing this step before the for loop.
Cheers
0