Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple problem

 
kanika dua
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I print values stored in the array in this program. I am building the name of the array and storing as a string-

Thanks for any help!!
[ June 04, 2002: Message edited by: Dirk Schreckmann ]
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you cannot use this:
for(int i=0; i<arr.length; i++) {
System.out.println(arr[i]);
}
Irene Loos
 
kanika dua
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building the name of the array dynamically from a user input(not showed in the code here). So till the user input is given I wouldn't know which array values I have to print.
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kanika,
Could you please post the rest of your code?
 
kanika dua
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry for not posting the code earlier. I haven't still written the entire code but just this module-

Here I want to print the inventory values for the month which is in turn input by the user. This code prints...jan[1] jan[2]..and not the actual values of the jan array.
Thanks
[ June 05, 2002: Message edited by: Dirk Schreckmann ]
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly, this should be able to solve your problem:

[ June 05, 2002: Message edited by: Irene Loos ]
 
kanika dua
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Irene.. I appreciate your reply and yes thats one way to achieve what I was trying to do. But I am still curious to know if we could do the following:
int[] arr = {1,2};
String str = "arr"+"[0]"; System.out.println(str);
and get the actual value stored in the array.
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kanika,
You will have to loop through array in order to get all the members or specifically tell what member you want (arr[1], arr[5],...). This is just the way arrays are made...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic