Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array woes

 
Sam Smythe
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to do a 2 dimensional array where size, beginning number and end number are passed in through the parameter. I keep getting an illegal start erro on the first dimension when I try to compile. I left the 2nd dimension as simple integers for now because if I can get the first half working, I can get the second half working. Any suggestions/direction would be appreciated.

 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to be more specific about what you are trying to achieve.
The code you provided does not compile at all.

Can you explain what this code is supposed to do (it can't work, but I can not figure out what it should do)?
[ February 13, 2007: Message edited by: bart zagers ]
 
Sam Smythe
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am supposed to do is fairly vague, and I think that is the problem. I have pasted it below. I am not yet concerned about the second method. I think I know what to do. It is just getting those parameters to set the size, begininning and end limits, and generate the numbers that get put in the array. I know how to create a 2 dimensional where specific values are passed in. I just don't know how to generate them using those guidelines, then pass them in. Every example I have found involves creating the array and passing in specific, pre-determined values.

Write a method that creates and initializes a two-dimensional array of double. The size of the array is determined by the arguments of the method, and the initialization values are a range determined by beginning and ending values that are also arguments of the method. Create a second method that will print the array generated by the first method. In main(), test the methods by creating and printing several different sizes of arrays.
 
Anton Uwe
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a little code sniplet to get you to the right path...
 
Sam Smythe
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's similar to the examples I have, but is still just creating the array with specific values. What I can't seem to do is generate numbers, from a certain number to a certain number, and make the array an exact size based upon the variable passed through to the parameter.
 
Anton Uwe
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK... take a look at this
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The size of the array is determined by the arguments of the method


How do you interpret the size of a two-dimensional array? In your example, you give your method a single size parameter.
Take for example a size of 5, how would the resulting array look like?

(Another approach would be to use 2 variables, one for each dimension.)
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic