This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with arrays

 
Troy Johnson
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic