aspose file tools*
The moose likes Beginning Java and the fly likes Simple problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple problem" Watch "Simple problem" New topic
Author

Simple problem

kanika dua
Greenhorn

Joined: Apr 17, 2002
Posts: 5
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

Joined: Apr 15, 2002
Posts: 78
Why you cannot use this:
for(int i=0; i<arr.length; i++) {
System.out.println(arr[i]);
}
Irene Loos


Irene Loos
kanika dua
Greenhorn

Joined: Apr 17, 2002
Posts: 5
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

Joined: Apr 15, 2002
Posts: 78
Kanika,
Could you please post the rest of your code?
kanika dua
Greenhorn

Joined: Apr 17, 2002
Posts: 5
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

Joined: Apr 15, 2002
Posts: 78
If I understand you correctly, this should be able to solve your problem:

[ June 05, 2002: Message edited by: Irene Loos ]
kanika dua
Greenhorn

Joined: Apr 17, 2002
Posts: 5
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

Joined: Apr 15, 2002
Posts: 78
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple problem