Results 1 to 2 of 2
  1. #1
    osval is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default How to get the max value from a list

    I need to find the max value from a lot of records. this is my code

    Java Code:
    double max = 0.0;
    for (int i=1; i<size; i++){
    max = data[0];
    if (data[i]>max)
    {
    max = data[i];
    }
    System.out.println(max);

    But it saves the last highest number on the list and it doesn't compare the values.
    How can I get it to find the max value from the entire list?

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Java Code:
    double max = 0.0;
    max = data[0];
    for (int i=1; i<size; i++)
      {
      if (data[i]>max)
        {
        max = data[i];
        }
    System.out.println(max);
    That should work better.

Similar Threads

  1. Members List
    By Eranga in forum Suggestions & Feedback
    Replies: 11
    Last Post: 01-17-2008, 10:41 AM
  2. To display as a list
    By yuvi461 in forum New To Java
    Replies: 2
    Last Post: 01-09-2008, 12:06 PM
  3. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 03:42 AM
  4. list
    By Zensai in forum New To Java
    Replies: 3
    Last Post: 11-20-2007, 07:22 AM
  5. Link List
    By one198 in forum New To Java
    Replies: 0
    Last Post: 10-14-2007, 01:33 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
  •