Anil Philip wrote:
Carey Brown wrote:
Not true. A simple loop, for example, would not have needed static member variables. It could use local variables.Anil Philip wrote:The method provided by HackerRank was static and so I had to use static member variables.
I do not wish to use loops. I want to use lambdas and streams to improve my understanding and facility with them.
Anil Philip wrote:
Stephan van Hulst wrote:Great, you made it work. Now, never write code like that ever again.
Either use a simple for-loop, or use a collector.
Huh? I am quite proud of what I wrote.![]()
Campbell Ritchie wrote:
I already have.Anil Philip wrote:. . . Can you please share your code using collectors? . . .
I told you that calling a List arr was a bad idea. It has confused you and that code won't compile because you are using Arrays.stream() as I did whan I thought it was an array.Anil Philip wrote:. . .
There are three kinds of actuaries: those who can count, and those who can't.
Campbell Ritchie wrote:. . . you aren't allowed to add fields to your class? . . .
Anil Philip wrote:Since all the 3 approaches worked and passed their test cases, they are apparently okay with adding the member variables.
It also doesn't mean it is correct code; the tests might have missed a corner case for which the code fails.Stephan van Hulst wrote:. . . The fact that something works, does not mean . . . .
Stephan van Hulst wrote:
Anil Philip wrote:Since all the 3 approaches worked and passed their test cases, they are apparently okay with adding the member variables.
Unit tests do not check for coding style.
The fact that something works, does not mean that it is also clean, maintainable code.
You need lots more practice. Show us some more code and let us improve it for youAnil Philip wrote:. . . I never pass these type of coding interview tests
Campbell Ritchie wrote:Nice, Piet, but please explain a bit more in case OP isn's familiar with a Collector like “all Gaul,” “divided into three parts.”
Campbell Ritchie wrote:Would you have any misgivings about precision if you are doing multiple floating‑point additions?
There are three kinds of actuaries: those who can count, and those who can't.
Stephan van Hulst wrote:In this case, there should be no problems with precision. Floating point values can represent integers exactly, so summing them should lead to no loss of accuracy or precision.
Piet Souris wrote:
Stephan van Hulst wrote:
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah! So that is what _ was reserved for. I knew it was some sort of unnamed variable but had never seen it used.Rob Spoor wrote:. . . reallowed since Java 22 . . .
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|