Results 1 to 2 of 2
  1. #1
    Hannguoi is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default How to add an integer to a array element and the store that backinto an array.

    Hello everyone i'm new to java and never had any computer programming before.
    and i'm current doing a project for school and i have a few question on the coding of an array.
    Here is part of my program.
    PHP Code:
    int []counts = new int [maxHeads + 1]; 
        for(int i = 0; i <counts.length; i++)
              counts[i] = counts[i] * (int)((maxLength/maxCount) + 0.5);
    /*
    This is what i wanted to do 
    "Now multiply each value in the counts array by the MAX length we want for bars (maxLength) 
    and divide by the largest value found (“maxCount”).  Remember the limitations of multiplication 
    and division for integer variables.  You will need to cast the integers to float or double for the 
    calculation and cast the result back to integer to [COLOR="Red"][B][U]update the value in each 
    counts array element[/U][/B][/COLOR]. It is also a good idea to add 0.5 to the float or double 
    value before casting it back to an integer.  That causes the code to round-off the value during 
    the conversion rather than truncate the value." */
    so please help ty in advance

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    please be more specific. what is your problem? Do you not know how to add, subtract using java arrays?
    i have a few question on the coding of an array.
    please list them.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. How do you store a random integer in an array?
    By Unknown in forum New To Java
    Replies: 6
    Last Post: 03-21-2010, 10:40 PM
  2. Passing integer array from javascript to java
    By lavanyashastri in forum New To Java
    Replies: 1
    Last Post: 02-21-2009, 06:02 AM
  3. adding list to an array element
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 09-25-2008, 04:23 AM
  4. Unique element in an array
    By revathi17 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 08:44 AM
  5. Max element in an Array
    By mew in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 05:26 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
  •