DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    R Cross Guest

    Arrays (for a raise)


    I need to write the code that will find the maximum value in an integer array.
    I'm stuck with what to do in the for loop. I won't compile at this point.

    class ArrayTester
    {
    public static main void (String args[])
    {

    int intArray [] = new int[25];
    int maxValue;

    public void init()
    {

    for (int i = 0; i < intArray.length; i++)
    {

    }

    }

    }//end main











    }//end class

  2. #2
    Paul Clapham Guest

    Re: Arrays (for a raise)


    > class ArrayTester
    > {
    > public static main void (String args[])
    > {
    >
    > int intArray [] = new int[25];

    // presumably the array will have some numbers put into it elsewhere
    > int maxValue;
    >
    > public void init()
    > {

    maxValue = Integer.MIN_VALUE; // before you start, max value
    is - infinity
    > for (int i = 0; i < intArray.length; i++)

    maxValue = Math.max(maxValue, intArray[i]); // replace max value by
    array entry if larger
    > {
    >
    > }
    >
    > }
    >
    > }//end main
    > }//end class




Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links