-
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
-
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
Forum Rules
|
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
|
Bookmarks