JavaPerspective.com >
Beginner Tutorials >
5. Java in Practice >
5.8. Java code exercises >
5.8.3. Code exercise 3
5.8.3. Code exercise 3
Last updated: 27 January 2013.
Write a method named getMaximum(int[] array) that returns the maximum value of the given array argument. If the array argument is null, the method returns 0.
public final class Practice {
public int getMaximum(int[] array){
// the code goes here
}
}
public int getMaximum(int[] array){
// the code goes here
}
}
public final class Practice {
public int getMaximum(int[] array){
if(array == null)
return 0;
int maximum = array[0];
for(int value : array){
if(value > maximum)
maximum = value;
}
return maximum;
}
}
public int getMaximum(int[] array){
if(array == null)
return 0;
int maximum = array[0];
for(int value : array){
if(value > maximum)
maximum = value;
}
return maximum;
}
}
You are here :
JavaPerspective.com >
Beginner Tutorials >
5. Java in Practice >
5.8. Java code exercises >
5.8.3. Code exercise 3
Next tutorial : JavaPerspective.com > Beginner Tutorials > 5. Java in Practice > 5.8. Java code exercises > 5.8.4. Code exercise 4
Next tutorial : JavaPerspective.com > Beginner Tutorials > 5. Java in Practice > 5.8. Java code exercises > 5.8.4. Code exercise 4