Results 1 to 13 of 13

Thread: arrays

  1. #1
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default 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. #2
    matt_well's Avatar
    matt_well is offline Member
    Join Date
    Jul 2008
    Posts
    59
    Rep Power
    0

    Default

    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. #3
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    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

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    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. #5
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    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. #6
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    hello norm can u check the code that i sent you and tell me what it means.
    Please

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    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. #8
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    thanks norm
    this is really a nice example to help me go aroung

  9. #9
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    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. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    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. #11
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

    Default

    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. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    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. #13
    hasysf is offline Member
    Join Date
    Jul 2008
    Posts
    19
    Rep Power
    0

Similar Threads

  1. Help on Arrays...
    By cuellar14 in forum New To Java
    Replies: 4
    Last Post: 07-25-2008, 09:16 PM
  2. Arrays
    By bunbun in forum New To Java
    Replies: 1
    Last Post: 04-09-2008, 03:24 AM
  3. new to arrays
    By jimJohnson in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 03:45 PM
  4. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 11:08 PM
  5. arrays help
    By Warren in forum New To Java
    Replies: 6
    Last Post: 11-23-2007, 08:23 PM

Posting Permissions

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