-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrongestNeighbour.java
More file actions
41 lines (28 loc) · 1021 Bytes
/
StrongestNeighbour.java
File metadata and controls
41 lines (28 loc) · 1021 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
32
33
34
35
36
37
38
39
40
41
//Window slidilng method-----------------
import java.util.Scanner;
class StrongestNeighbour {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array :");
int sizeOfArray=sc.nextInt();
System.out.println("Enter the array :");
int arr[]=new int[sizeOfArray];
for(int i=0;i<sizeOfArray;i++){
int x=sc.nextInt();
arr[i]=x;
}
maximumAdjacent(sizeOfArray,arr);
}
public static void maximumAdjacent(int n,int ar[]){
int k=2,j,max; //k=window size
for(int i=0;i<n-1;i++){
max=ar[i];
for(j=1;j<k;j++){ //for sliding the window length
if(ar[j+i]>=max){
max=ar[j+i];
}
}
System.out.println("output :"+max+" ");
}
}
}