• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I pass an array as an argument to a Constructor?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here is my situation. I have this array in my demo program ---> double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0 }; I need to pass this as an argument to my parametrized constructor. I know how to do it going down the line with user input. But this for some reason is throwing me for a loop since I am just given an array instead of having a user input the numbers.

Edit: *facepalm* Ok it never fails right after I post an issue I figure it out just like that.

Anyway for anyone searching for this issue here is how I did it.

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Colby Allen wrote:Edit: *facepalm* Ok it never fails right after I post an issue I figure it out just like that.

Anyway for anyone searching for this issue here is how I did it.


Thanks for posting the answer for others who have the same question!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a hint: you can use System.arraycopy to do the copying for you. So instead of you can simply write This means: copy SIZE elements from s to scoreArray, starting at 0 for both s and scoreArray.
 
Colby Allen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Colby Allen wrote:Edit: *facepalm* Ok it never fails right after I post an issue I figure it out just like that.

Anyway for anyone searching for this issue here is how I did it.


Thanks for posting the answer for others who have the same question!



No problem. I hate a wasted post, so if somebody searches for this post then I want them to be able to find what they are looking for. Also this forum has helped me plenty, so I like to give back when I can.

Rob Prime wrote:Just a hint: you can use System.arraycopy to do the copying for you. So instead of you can simply write This means: copy SIZE elements from s to scoreArray, starting at 0 for both s and scoreArray.



Thanks for the tip! I will try to remember that in the future.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic