-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCdc.java
More file actions
26 lines (23 loc) · 749 Bytes
/
Cdc.java
File metadata and controls
26 lines (23 loc) · 749 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
package accentureQ;
import java.util.Scanner;
public class Cdc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input length of array");
int n = sc.nextInt();
int sub = Integer.MIN_VALUE;
int [] arr = new int[n];
System.out.println("Enter the array");
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (arr[i] < arr[j]){
if (j - i > sub) sub = j - i ;
}
}
}
System.out.println("Maximum difference is " + sub);
}
}