Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

creating variables in a loop

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody tell me how to dinamically create vectors. Here's the idea
int numcols = 4;
for (int i = 0; i < numcols; i++) {
//create 4 vectors
Vector v + i = new Vector();
}
and the outcome needs to be something like:
v1
v2
v3
v4
Please, please, PLEASE!!
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at arrays.
 
Dalibor Toth
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, need vectors!
BTW, I took a look into arrays but could not find anything that could help. Can you post some algorythm?
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, you need vectors.
but an array of vectors, eh?
/peter
 
Dalibor Toth
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd still need to initialize those (f...) vectors.
In html page that has applet tag calling my applet, there is a param tag saying how many columns do I have (say, 4). The applet reads the tag and initializes as much vectors as the param tag says - so in this case - 4. If I would set that parameter to 7, the applet would create 7 vectors. Etc.
Can somebody, please, post some code? It would be appreciated.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int numcols = 4;
Vector v[] = new Vector[numcols];
for (int i = 0; i < numcols; i++) {
//create 4 vectors
Vector v[i] = new Vector();
}
??? is this what you want ??
 
Dalibor Toth
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get these errors:
sc.java:35: ']' expected
Vector v[i] = new Vector();
^
sc.java:35: v is already defined in start()
Vector v[i] = new Vector();
^
2 errors
What's wrong?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that v was already declared, so putting "Vector" in front of v a second time is incorrect. Replace
<pre> Vector v[i] = new Vector();</pre>
with
<pre> v[i] = new Vector();</pre>
[This message has been edited by Jim Yingst (edited August 22, 2001).]
 
Dalibor Toth
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, enormously!
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic