This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Simple problem  RSS feed

 
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 ]
 
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!