1. Member
Join Date
Jul 2008
Posts
19
Rep Power
0

## arrays

Hello this is my first question on this forum
I need to ask a question
what is the difference in storing a value in array and adding a value in array
my psuedocode and both the requirements provided separately

2. I read my Java book saying that
double temperature[]; // declare array
temperature = new double[10]; //allocate space for array
Which means the temperature have ten double storage location.

3. Member
Join Date
Jul 2008
Posts
19
Rep Power
0
yaa thats true but the thing is that is there difference to store a value entered by a user in an array
and add the value entered by a user in the array
i am confused

4. to store a value entered by a user in an array
and add the value entered by a user in the array
That sounds like two different ways to same the same thing.
To put a value into an array: arrayN[i] = value;
Not sure what you mean by add. Is 'to add' the same as to sum up two items? To add x to y you would code x = x + y;
But when talking about an array, to add to an array could mean to make the array longer (add to its length) or it could mean to add to an element in an array: arrayN[i] += value;

Could you give an example of the two things you are asking about. In both cases you have a value entered by a user.
Now what are the two things you want to do with that value?

5. Member
Join Date
Jul 2008
Posts
19
Rep Power
0
Sure
/* Compare the user input to the unique numbers in the array using a for
31 statement. If the number is unique, store new number */
32
33 /* add the user input to the array only if the number is not already
34 in the array */
35 if ( !containsNumber )
36 {
37 /* Write code to add the number to the array and increment
38 unique items input */
39 } // end if

this is the psuedocode for the part of the program
any suggestions?

6. Member
Join Date
Jul 2008
Posts
19
Rep Power
0
hello norm can u check the code that i sent you and tell me what it means.

7. I'll restate the problem.
If you have a some playing cards (an array) and a user hands you a new playing card, look thru the cards you already have(use a for loop, comparing the new one to each one you have) and if the new card is unique(you get to the end of the cards and don't see any matches), add it to the group(insert the new one at the end).

8. Member
Join Date
Jul 2008
Posts
19
Rep Power
0
thanks norm
this is really a nice example to help me go aroung

9. Member
Join Date
Jul 2008
Posts
19
Rep Power
0
Compare the user input to the unique numbers in the array using a for
31 statement. If the number is unique, store new number */

what is meant by that norm

10. Where did you get the problem statement? Do you have an instructor or a textbook?
The for statement is used to control looping. for(i=0; i <10; i++)
The == operand is used for comparing two primitives like numbers or characters. if(a == b)
The if statement is used to control execution based on a condition. (a == b)
Unique is an english word.
To store is to save the number.

11. Member
Join Date
Jul 2008
Posts
19
Rep Power
0
hello sir
I dont think i was expecting this answer from you. But anyways thanks for replying and by storing i meant by storing in the simple variable or in an array
thanx

12. storing in the simple variable or in an array
int x = value; // store value in simple variable
x[i] = value; // store value in an array

13. Member
Join Date
Jul 2008
Posts
19
Rep Power
0

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•