Determining the smallest number in an array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Determining the smallest number in an array

  1. #1
    Join Date
    Feb 2006
    Posts
    8

    Determining the smallest number in an array

    System.out.println("The smallest: " + badSalesperson + " made the least money: " + smallest + "Try Harder!" );

    }
    } [/PHP]
    Last edited by leospyder; 02-05-2009 at 12:20 AM.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The best way to make these things work is set "smallest" to be larger than the largest possible value ( such as 10000000 or +infinity) and set "largest" to be a value smaller than the smallest possible value (such as -1 if all values are going to be positive ..., are -infinity if negative values are possible). Then you will, for sure, have something smaller/larger ...

  3. #3
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    there is a bug in the code:
    Code:
            if (sales[i]>largest)
                {
                    largest = sales[i];
                    GreatSalesperson = i;
                }
                 
            if (sales[i]<smallest)
                {
                    smallest = sales[i];
                }
            }
    you set GreatSalesperson, but not badSalesperson

Similar Threads

  1. Dynamically allocating a 2d array
    By nnp in forum C++
    Replies: 6
    Last Post: 11-01-2005, 09:05 AM
  2. Replies: 1
    Last Post: 06-27-2005, 05:23 PM
  3. Replies: 2
    Last Post: 04-15-2005, 09:06 PM
  4. Replies: 3
    Last Post: 01-11-2001, 11:29 AM
  5. Replies: 3
    Last Post: 08-02-2000, 01:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center