• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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...
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!