-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise1421.java
More file actions
44 lines (40 loc) · 1.31 KB
/
Copy pathExercise1421.java
File metadata and controls
44 lines (40 loc) · 1.31 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
public class Exercise1421
{
public static void main(String[] args)
{
int[] a = {2,1,8,7,2,2,7,5,3,2};
int i = 0;
int j = 0;
int count = 1;
int longestCount = 0;
int startOfLongestCount = 0;
while(i < a.length-1)
{
if(a[i] < a[i+1])
{
j = i + 1;
count = 1;
while(a[i+1] == a[i+2])
{
count = count + 1;
i = i + 1;
}
if(count > longestCount)
{
longestCount = count;
startOfLongestCount = j;
if(a[i+1] > a[i+2] && count > 1)
{
System.out.println("The plateau's location starts at the index: "+ startOfLongestCount);
System.out.println("The length is "+ longestCount);
}
else
{
System.out.println("Did not find any plateaus because either first the value after is larger than the numbers in the plateau OR the the count of the number is less than 2");
}
}
}
i=i+1;
}
}
}