0

How can I fill this array with numbers (1 to 10)

private Account[] accounts = new Account[10]

22nd Dec 2018, 4:47 PM
Adem E
Adem E - avatar
3 ответов
+ 1
If you want new accounts array Replace accounts[i] = i+1; With accounts[i] = new Account();
28th Dec 2018, 8:27 AM
🇵🇰 Danish Khan 🇵🇰
🇵🇰 Danish Khan 🇵🇰 - avatar
+ 1
A method in same class because the Account is private, using a for loop public fillArray() { // can also be private if you only call it from constructor for(int i=0;i<10;i++){ accounts[i] = i+1; } }
22nd Dec 2018, 8:14 PM
🇵🇰 Danish Khan 🇵🇰
🇵🇰 Danish Khan 🇵🇰 - avatar
0
thanks for answer, but didn't work :| this was about array of objects. and I have to create 10 objects from Account class.
28th Dec 2018, 7:43 AM
Adem E
Adem E - avatar