• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array dimensioning  RSS feed

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to define the size of an array using variables?

Ex:
 
Peter Miklosko
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Why you asking?
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you can also define the size of an array using any expression or method call that returns an integer.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, although in your code snippet you're trying to initialize a static with non-static vars, which won't work.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you have to make sure the sizes are not negative.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
questions like this can often be answered by trying it out. On every machine where i work, i have a little sandbox directory. I have a few basic code templates there - a basic java file written with a (empty) main method, for example. Then, if i want to try something out, i just fire up my editor, open the file, and stick in some code.

You probably could have answered the question yourself that way faster than posting it here. Not that we mind answering questions, but people generally learn better when they try it for themselves.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!