Results 1 to 4 of 4
  1. #1
    Dimitri is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Print the sum of elements, determined by zero elements

    Hello, guys.
    I have next csv file:
    3;qw;4;5.1;2.7
    15;;;k;5
    1;3.14;fgh;5
    0;;e1;2;3
    -2.3;a;b;c
    b;d;e



    And i added this data from file to String array[][] and i need print the sum of elements, determined by zero elements. Create this result in the string. The output format see in the example: sum = 5.1 + 3.14 + 0 = 8.24

    How do I do, I understand the algorithm, but the syntax does not know. Please, help

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Print the sum of elements, determined by zero elements

    Quote Originally Posted by Dimitri View Post
    i need print the sum of elements, determined by zero elements.
    I have no idea what that means.

  3. #3
    Dimitri is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default Re: Print the sum of elements, determined by zero elements

    File in.csv (text data separated by semicolon) contains some sequence of lines with any number of elements in each line.
    Let the initial element of any line has an index 0. Its value determines the index of an element in the line you should work with.
    1) Print the sum of elements, determined by zero elements. Create this result in the string. The output format see in the example below.
    2) Print the number of lines with “errors”.

    The example of the file in.csv:
    3;qw;4;5.1;2.7
    15;;;k;5
    1;3.14;fgh;5
    0;;e1;2;3
    -2.3;a;b;c
    b;d;e
    Output:
    sum = 5.1 + 3.14 + 0 = 8.24
    error-lines = 3

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Print the sum of elements, determined by zero elements

    <lightbulb>
    I see what the problem is.

    Read a line
    Split it by semi-colon
    Read first value (index 0)
    Check to see if value is valid (positive and less than length)
    If it is valid use it as index into array and add value at that index to sum
    Else increment error count

Similar Threads

  1. get all elements in JTree
    By jperson in forum New To Java
    Replies: 1
    Last Post: 06-25-2011, 03:47 PM
  2. Replies: 2
    Last Post: 12-02-2010, 04:18 AM
  3. Replies: 7
    Last Post: 08-30-2010, 03:35 PM
  4. DefaultListModel Elements
    By jboy in forum New To Java
    Replies: 7
    Last Post: 10-24-2009, 03:23 AM
  5. what does <Elements> mean
    By JordashTalon in forum New To Java
    Replies: 1
    Last Post: 01-31-2009, 10:19 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
  •