Arrays (for a raise)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Arrays (for a raise)

  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




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