mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-20 02:04:47 +08:00
add more
This commit is contained in:
26
Maths/FindMax.java
Normal file
26
Maths/FindMax.java
Normal file
@ -0,0 +1,26 @@
|
||||
package Maths;
|
||||
|
||||
public class FindMax {
|
||||
|
||||
//Driver
|
||||
public static void main(String[] args) {
|
||||
int[] array = {2, 4, 9, 7, 19, 94, 5};
|
||||
System.out.println("max = " + findMax(array));
|
||||
}
|
||||
|
||||
/**
|
||||
* find max of array
|
||||
*
|
||||
* @param array the array contains element
|
||||
* @return max value
|
||||
*/
|
||||
public static int findMax(int[] array) {
|
||||
int max = array[0];
|
||||
for (int i = 1; i < array.length; ++i) {
|
||||
if (array[i] > max) {
|
||||
max = array[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user