This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help with arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with arrays" Watch "Help with arrays" New topic

Help with arrays

Troy Johnson

Joined: Sep 24, 2003
Posts: 20
Hello. I am trying to fill this entire array with new data objects using "for" loops adn then set the value of each objects variable i in the array by calling each objects setl() method. I am a little confused and lost about trying to add these modifications. Could anyone offer any suggestions or ideas. Again, I am new to Java and I greatly appreciate everyones help. Thanks.
Here is my code so far
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
check the modified code...
please learn the for loop and array concepts..
public class array
public static void main(String[] args){
Data d[] = new Data[5];

for (int i = 0; i < 5; i++)
d[i] = new Data();
d[i].setI((int)(Math.random() * 5 + 1));
class Data
private int i = 0;
public void setI(int parm){
i = parm;
public int getI(){
return i;

Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
I agree. Here's the link:
subject: Help with arrays
jQuery in Action, 3rd edition