0
How do.we add same statement in 3 different methods in java
I have created few methods and I want to add a same sttemenf all methods.(sum=sum+1) how can I get updated value to a methods by methods..
3 Answers
+ 2
So let me make sure I understand this correctly. You have written a few methods (let's say 3) and all 3 of those methods you want each of them to do sum=sum+1? However, the last,part of your question isn't clear to me. I am not sure what you mean by "get updated value to a methods by methods". If you can clarify this piece and verify my assumption regarding those methods is correct, then I can help you more.
As a side note, I would recommend adding in a tag of JAVA since this is a java based question. Might help in getting some answers faster.
Thanks.
+ 1
Alright. Then this is super easy. All you need to do is a nested method call. What this means is you call the method you are in from inside the method. This way you aren't calling multiple different methods, are keeping your code simplified, and are being smart with your coding.
There are tons of articles out there about this. So Google will definitely be your friend here. Now, if you do get stuck, don't hesitate to pigsty the code you have here and I or someone else will be more than happy to help you. :)
Good luck and look forward to any further help you may need.
0
updated mean ,value of sum...just think in the 1st method value of some goes 1,and in the 2nd method it should add 1 for 1st methods value.