Results 1 to 13 of 13
Thread: arrays
- 07-27-2008, 07:26 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 19
- Rep Power
- 0
- 07-27-2008, 07:53 PM #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.
- 07-27-2008, 07:57 PM #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
help please
- 07-27-2008, 08:07 PM #4
That sounds like two different ways to same the same thing.to store a value entered by a user in an array
and add the value entered by a user in the array
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?
- 07-27-2008, 08:32 PM #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?
- 07-27-2008, 09:07 PM #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.
Please
- 07-27-2008, 10:38 PM #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).
- 07-27-2008, 11:33 PM #8
Member
- Join Date
- Jul 2008
- Posts
- 19
- Rep Power
- 0
thanks norm
this is really a nice example to help me go aroung
- 07-27-2008, 11:36 PM #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
- 07-27-2008, 11:52 PM #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.
- 07-27-2008, 11:59 PM #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
- 07-28-2008, 02:33 AM #12
int x = value; // store value in simple variablestoring in the simple variable or in an array
x[i] = value; // store value in an array
- 07-28-2008, 02:38 AM #13
Member
- Join Date
- Jul 2008
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
Help on Arrays...
By cuellar14 in forum New To JavaReplies: 4Last Post: 07-25-2008, 08:16 PM -
Arrays
By bunbun in forum New To JavaReplies: 1Last Post: 04-09-2008, 02:24 AM -
new to arrays
By jimJohnson in forum New To JavaReplies: 1Last Post: 04-08-2008, 02:45 PM -
2D-Arrays
By kbyrne in forum New To JavaReplies: 1Last Post: 02-07-2008, 10:08 PM -
arrays help
By Warren in forum New To JavaReplies: 6Last Post: 11-23-2007, 07:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks