Results 1 to 13 of 13
Thread: Array Issues
- 12-12-2011, 01:28 PM #1
Member
- Join Date
- Nov 2011
- Location
- Australia
- Posts
- 28
- Rep Power
- 0
Array Issues
Hi everyone,
I just have a quick question that probably has a really simple answer too. I've only just begun using arrays and I was wondering if it was possible to have an array that has 5 values initialised but also has room for it to be expanded, for example 15 extra positions giving a total of 20 with the initialised values.
Thanks :)
- 12-12-2011, 01:37 PM #2
Re: Array Issues
What happens when you code it and compile it?
- 12-12-2011, 01:40 PM #3
Member
- Join Date
- Nov 2011
- Location
- Australia
- Posts
- 28
- Rep Power
- 0
Re: Array Issues
That's my problem, I'm not sure how I would code it.
I know that if I was just to make an array without any initialised values I would write
private int sandwichesPurchased[] = new int[20]; for example
and if I was to initialise values I would do this
private int sandwichesPurchased[] = {1,2,3 . . .};
but I'm not sure how I would incorporate the both of them into one.
- 12-12-2011, 01:41 PM #4
Re: Array Issues
Ask the compiler if your code is valid.
- 12-12-2011, 01:42 PM #5
Member
- Join Date
- Nov 2011
- Location
- Australia
- Posts
- 28
- Rep Power
- 0
Re: Array Issues
I complied it with this as the array
private int sandwichesPurchased[] = new int[20];
and there are no errors.
- 12-12-2011, 01:49 PM #6
Re: Array Issues
If the compiler doesn't complain, then it should work.
- 12-12-2011, 01:52 PM #7
Member
- Join Date
- Nov 2011
- Location
- Australia
- Posts
- 28
- Rep Power
- 0
Re: Array Issues
But when I compile this array
private int sandwichesPurchased[] = new int[20];
there are no values initialised in the array, all we know is that there are 20 positions in it.
I was wondering if I could make an array that has initialised values as well as space if other values were needed to be input in later.
- 12-12-2011, 01:57 PM #8
Re: Array Issues
Did you ask the compiler?I was wondering if I could make an array that has initialised values as well as space if other values were needed to be input in later.
- 12-12-2011, 01:58 PM #9
Member
- Join Date
- Nov 2011
- Location
- Australia
- Posts
- 28
- Rep Power
- 0
Re: Array Issues
How do I ask the compiler? Sorry for my lack of knowledge
- 12-12-2011, 02:00 PM #10
Re: Array Issues
Type in a line of code and compile it.
- 12-12-2011, 02:03 PM #11
Member
- Join Date
- Nov 2011
- Location
- Australia
- Posts
- 28
- Rep Power
- 0
Re: Array Issues
I am not sure what I would put into so I could compile it.
- 12-12-2011, 02:23 PM #12
Banned
- Join Date
- Dec 2011
- Posts
- 143
- Rep Power
- 0
Re: Array Issues
Last edited by 2by4; 12-12-2011 at 02:28 PM.
- 12-12-2011, 10:02 PM #13
Similar Threads
-
Array traversal issues
By sondratheloser in forum New To JavaReplies: 3Last Post: 08-13-2012, 12:49 AM -
help! shapes output and array issues!
By japgoth in forum New To JavaReplies: 2Last Post: 01-25-2011, 09:49 PM -
jdk issues
By artemff in forum New To JavaReplies: 3Last Post: 01-02-2010, 03:18 AM -
Array issues
By joka22 in forum New To JavaReplies: 6Last Post: 10-07-2008, 11:05 AM -
Array issues
By Neo82 in forum New To JavaReplies: 1Last Post: 12-31-2007, 03:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks