This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Steven Desilets

Ranch Hand
+ Follow
since Apr 04, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
36
Given in last 30 days
15
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steven Desilets

Alright Thank you
5 days ago

Campbell Ritchie wrote:

Steven Desilets wrote:. . . Is there a way to optimize the code? . . .

Yes, of course there is. You use n × (n + 1) ÷ 2. That is probably not what you are supposed to do if this is a test of your ability to write loops.

. . . Also at first,i have choose a int for the sum . . .

As Fred has shown, you will overwhelm the range of an int (−2147438648…2147483647 (inclusive)), to which the answer is to declare sum as type long, not double. A long has a range with 19 digits starting 922..... You have now seen what an overflow error looks like.



Well i just test again and the number is not negative, i got this number:

405761115

but since the the max range is 2147483647 , do this number is the result of a integer overflow?





5 days ago

Campbell Ritchie wrote:

Steven Desilets wrote:. . . Is there a way to optimize the code? . . .

Yes, of course there is. You use n × (n + 1) ÷ 2. That is probably not what you are supposed to do if this is a test of your ability to write loops.

. . . Also at first,i have choose a int for the sum . . .

As Fred has shown, you will overwhelm the range of an int (−2147438648…2147483647 (inclusive)), to which the answer is to declare sum as type long, not double. A long has a range with 19 digits starting 922..... You have now seen what an overflow error looks like.



Thank now i understand.
5 days ago
I forget to ask, but why choose double over integer for the sum?
Thank
6 days ago
Thank you for your answer
6 days ago

Tim Holloway wrote:A famous mathematician whose name I forget was once punished for being too smart for his own good by being assigned the task of adding up all numbers from 1 to 1000 or so. He solved it in minutes by noting that 1+999 = 2+998 = 3.997 ... and thus - if my math is correct - the sum was simply (1000/2) * 1000.

That solution is probably why your own excercise has those extra little qualifications, lest you do likewise. However, I would not be surprised to see a similarly exploitable pattern in this app, since if you apply a rule based on math, there's probably a way to optimise it in math.



Thank for your answer

Tim Holloway wrote:I'm not sure what "the numbers whose number of one hundred place is 2 or 3" means in English, though.



Maybe, hundred place digit, ten place digit,one place digit? Not sure
6 days ago
Hi everybody,  i need to write a program to calculate the sum of the numbers from 1 to 1,000,000 (including 1 and 1,000,000),but omitting the numbers which are divisible by three and the numbers whose hundred place digit is 2 or 3.

I  have write the code below:



Is there a way to optimize the code?Also at first,i have choose a int for the sum, but the result was a negative number, why that? It is because of the limitation of the integer?  

Thank you
6 days ago

Seriously though, if the program is for just one bank, then why even create a Bank class that you can instantiate? That's like creating a whole car manufacturing plant just to make a single car. It doesn't make a whole lot of sense



Now that you said that..it make total sense, i still learning!
3 weeks ago

Junilu Lacar wrote:

Steven Desilets wrote:Well yes, but for a program for only one specific Bank and all his branch ,it make more sense?


Well, if that's the way you want to live your life and you're sure that there will only ever be one instance of Bank created, go ahead. You can also choose to go through life wearing your shirts inside out and if you're fine with that, more power to you!  



lol

Well i may reconsider my logic  
3 weeks ago

Junilu Lacar wrote:

Steven Desilets wrote:Thank for the answer, well i was thinking since we can have one big bank by country,but we share all branch via these bank, it would make sense to make it static?


The problem is that Bank is a class and each instance of Bank would be a different bank, right? So you could conceivably do this:

So you have three different banks. By making the branches list static, that would make all three banks (and any other Bank objects you instantiate) share the same list of branches. Obviously, that's wrong. Each bank will have their own list of branches which means the branches field should not be static, it should be a non-static instance member.



Well yes, but for a program for only one specific Bank and all his branch ,it make more sense?
3 weeks ago
Thank you for your answer!
3 weeks ago

Adrian Grabowski wrote:You would need to add a method to the Bank class called getByBranchName or something similar

Also, on line 4, is that supposed to be static?



Thank for the answer, well i was thinking since we can have one big bank by country,but we share all branch via these bank, it would make sense to make it static?
3 weeks ago
Hello everybody, i have this class of a bank,


and a class of branch,


So in the Main class i do that:


My question is , when i create the Yukon instance , i add it to the arraylist branches, then i can access it by his object name, here "Yukon". But when i create a instance via the method createBranch, i add it to the arraylist branches too,but  after that, i cannot access this instance via his instance name because the name i give "newbranch" is only valid in the method scope.But is there a way to access the instance directly like the Yukon instance?

Thank you
3 weeks ago

Tim Holloway wrote:

Campbell Ritchie wrote:[here isn't that much difference between || and | in that present expression.



Yes, but there's a great deal of difference in this expression:


versus





Well ,for now what i have learn is ,the && and || operators "short-circuit", meaning they don't evaluate the right hand side if it isn't necessary.

The & and | operators, when used as logical operators, always evaluate both sides.

But thank all for all you explanation !

1 month ago