Results 1 to 5 of 5
- 01-07-2012, 11:19 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 31
- Rep Power
- 0
How can I set default value to Array
Hi
How do I assign a new default value to array variable. In my account class I have set the variable balance to be default 0. I am now creating an array of 10 accounts and want to give them a default balance of 50. Do I still have to set each of them like so or is there a way to set thedefault balance for the whole array.
or willJava Code:accounts[0].setBalance(50); accounts[1].setBalance(50);
accounts[].setBalance(50);
-
Re: How can I set default value to Array
You will need to use a for loop or foreach loop to loop through the array, setting the balance of each item held by the array.
- 01-07-2012, 11:23 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: How can I set default value to Array
I think it is best to do that with a constructor. Something like:
public Account (int balance = 0) {this.balance = balance};
- 01-07-2012, 11:26 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 31
- Rep Power
- 0
Re: How can I set default value to Array
Thanks Fubarable I will try that.
- 01-07-2012, 11:54 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Similar Threads
-
Copy Default table model to another default table model?
By greatmajestics in forum AWT / SwingReplies: 2Last Post: 04-28-2010, 04:08 PM -
How array elements gets default value
By Veangat in forum New To JavaReplies: 1Last Post: 03-07-2010, 01:29 PM -
default button SWT
By ashin in forum SWT / JFaceReplies: 0Last Post: 07-07-2009, 04:12 PM -
[SOLVED] Access to default session deniedAccess to default session denied
By jazz2k8 in forum NetworkingReplies: 1Last Post: 03-10-2009, 01:12 PM -
Default Button
By hiranya in forum AWT / SwingReplies: 2Last Post: 11-01-2007, 06:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks