please I need help , this task is eating my memory.
tell me how to solve the task.
thanks
who can give me the knowledge I need to solve this task
Under discussion
Comments (11)
- Popular
- New
- Old
You must be signed in to leave a comment
June Sung Park
5 April 2020, 01:41
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int maximum;
int N = Integer.parseInt(reader.readLine());
if (N > 0) {
maximum = Integer.parseInt(reader.readLine());
for (int i = 1; i < N; i++) {
int next= Integer.parseInt(reader.readLine());
if (next >= maximum)
maximum = next;
}
System.out.println(maximum);
}
}
0
Gellert Varga
31 March 2020, 20:41
Check your output, if you will input N=0!
And then you will see what's wrong.
0
Misiu
31 March 2020, 22:46
In conditions of this task N must be > 0.
0
Gellert Varga
31 March 2020, 23:07
But the task says also this:
"The program should not display anything if N is less than or equal to 0."
And if you will test this program with 0, then you will see it will display a number in this case.
0
Misiu
31 March 2020, 23:16
I mean task0532 "Task with alghoritms" (translated from Polish).
In that task (Polish version) there is only one condition for N, N > 0.
0
Gellert Varga
1 April 2020, 00:02
I use the english version. (But i would think the tasks are same.)
In this link:
https://codegym.cc/tasks/com.codegym.task.task05.task0532
you can read exactly this about this task:
"Write a program that:
1. reads a number N (must be greater than 0) from the console
2. reads N numbers from the console
3. Displays the maximum of the N entered numbers.
Requirements:
•
The program should read the numbers from the keyboard.
•
The program must display a number on the screen.
•
The class must have a public static void main method.
•
Don't add new methods to the Solution class.
•
The program should display the maximum of the N entered numbers.
•
The program should not display anything if N is less than or equal to 0."
- - - - - - - - - - - - - -
But there was already an example, that an unsaid task-condition caused test failing for me.
0
Misiu
1 April 2020, 00:09
OK. In Polish version there are 5 requirements only. There is no 6th requirement.
So we are right both ;)
0
Gellert Varga
1 April 2020, 18:47
OK:)
- - - - - - - - - - - - - -
I write an other case, it is worth considering.
It caused me a lot of headaches how to make passed my multiplication table program
( https://codegym.cc/tasks/com.codegym.task.task03.task0314 ).
My solutions worked absolutely well, i wrote several versions, but the verifier always gave me red.
Finally, i got a very good advice from a Level37-student.
Following his advice, my program passed immediately,
but this requirement was not included in the original criteria of the task!!
I paste the whole thing here:
" - You should not use static variables. It is generally poor practice to do so unless specifically needed, and a lot of tasks will automatically fail if you do use them. You should be able to pass this task by removing the static variables.
- I couldn't say why the validation system doesn't accept some solutions.
- Just remember to stay away from static variables in this course unless they specifically say to use or add them. I was failing a lot of tasks too when I was leveling up because of this.
>>To stay away from static variables - but just in this CodeGym-course? Otherwise, no problem with them? (I thought this was a general truth.)<<
- There is no problem with them. It is just generally poor deign to just use them wherever. It is better to use local variables and pass values around using method arguments. There are plenty of reasons why you would use them though, take something like a game where there is a player score. You can gain score by doing multiple different things, it wouldn't make sense to use a local variable there but a class variable (static)."
+1
Zachariasz Kluk
31 March 2020, 07:43
+1
Misiu
31 March 2020, 11:26
Kod poprawny.
Masz "throws IOException" za sygnaturą metody main(), import wymaganych bibliotek?
Wklej cały kod tego zadania.
0
Przemysław Dr
30 March 2020, 11:05
Hi, paste your code and we will try to help you.
0