//Given a number, find the sum of all the unique multiples of particular numbers up to
//but not including that number.
//
//If we list all the natural numbers below 20 that are multiples of 3 or 5,
//we get 3, 5, 6, 9, 10, 12, 15, and 18.
//
//The sum of these multiples is 78.
That line is imprecise; you certainly don't want nulls, but please use a different exception (NullPointerException) and a more accurate error message. Yes, you do have to be very precise when writing code. I can't see an empty set being a problem; you will simply get an empty OptionalInt and you can use orElse(0). And I can't see why negative numbers would be a problem.tangara goh wrote:. . .
Please avoid abbreviations; I have seen Google translate struggle with “Tks”.. . . . Tks.
Carey Brown wrote:Looks like set is never filled with anything so is all zeros.
What is the problem you are seeing?
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Tangara,
there is no need to have an int[] parameter. Read the exercise again. So you woulg get something like
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Tangara,
there is no need to have an int[] parameter. Read the exercise again. So you woulg get something like
There are three kinds of actuaries: those who can count, and those who can't.
What set? You haven't got a set anywhere. You only appear to have an array.tangara goh wrote:. . . then to use the set . . .
Piet Souris wrote:As I said, I could not find a method signature, and so I used 3 and 5 as in the example given.
But assuming the array is an array of possible divisors, in my example {3, 5}, you could have a helper method like:
and so you could have this method
Liutauras Vilda wrote:@OP
So you just need to incorporate into the template you have been given a code Piet wrote.
What is DSA?
i.e.
Or
Think which approach is better and why.
Carey Brown wrote:
There are three kinds of actuaries: those who can count, and those who can't.
Campbell Ritchie wrote:What I said in my last post suggests you can use that method in a functional style. But the example you showed in your first post has modifiers inconsistent with that. I don't like over‑specification like that, and my liking for that website you found has not increased.
Afraid I think you were rather unlucky. Don't know of any sites teaching OOP; sorry. Maybe somebody else will know.tangara goh wrote:. . . I thought that I was lucky to chance upon that site . . .
tangara goh wrote:I hope someone could pinpoint the mistakes. Tks.
Carey Brown wrote:Why not?
from javadocsstatic IntStream range(int startInclusive, int endExclusive)
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|