aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with arrays" Watch "Help with arrays" New topic
Author

Help with arrays

Troy Johnson
Greenhorn

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));
System.out.println(d[0].getI());
}
}
}
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 :-)
 
jQuery in Action, 2nd edition
 
subject: Help with arrays