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=0;
int count;
boolean first = true;
int n = Integer.parseInt(reader.readLine());
if (n > 0) {
for (count = 0; count < n; count++) {
int a = Integer.parseInt(reader.readLine());
if (first) {
maximum = a;
first = false;
}
maximum = (a > maximum ? a : maximum);
}
}else;
if (maximum <= 0)
;
else
System.out.println(maximum);
}
}
What does this want to happen for negative numbers?
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Ashish RajAnand
13 May 2020, 04:17
let take -2,-3,-4,-5 //ans = - 2
you set maximum =0;
then your output is 0.
correct it store first number in maximum
0
Brandon
13 May 2020, 05:13
I did. In mine, doing it your way my answer would be -2. It would be set in lines 22-25. I'm not sure how it's supposed to be set up, but I'm pretty sure my way works completely.
0
Ashish RajAnand
13 May 2020, 07:23solution
see at line 33-36 ad remove it.
this is reason your code not work for negative number.
simply print maximum
+3
Brandon
13 May 2020, 13:24
Thanks, I just misunderstood that last one.
0