| 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 :-)
|
 |
 |
|
|
subject: Help with arrays
|
|
|