-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocMinLocalMax.java
More file actions
31 lines (31 loc) · 862 Bytes
/
LocMinLocalMax.java
File metadata and controls
31 lines (31 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class LocMinLocalMax {
public static void main(String args[]) {
int a[] = {3, 7, 5, 2, -6, -7, -6} ;
int i ;
int max = -10000000 ;
int min = 10000000 ;
for (i = 0; i <= a.length - 2 ;) {
if (i > 0 && a[i] > a[i + 1] && a[i] > a[i - 1] ) {
System.out.println("Local max= " + a[i]) ;
}
if ( i > 0 && a[i] < a[i + 1] && a[i] < a[i - 1] ) {
System.out.println("Local min= " + a[i]) ;
}
if (a[i] > max) {
max = a[i] ;
}
if (a[i] < min) {
min = a[i] ;
}
i = i + 1;
}
if (a[a.length - 1] > max ) {
max = a[a.length - 1] ;
}
if (a[a.length - 1] < min) {
min = a[a.length - 1] ;
}
System.out.println("min =" + min);
System.out.println("Max= " + max ) ;
}
}