-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaximumindex.java
37 lines (35 loc) · 975 Bytes
/
Maximumindex.java
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
package myprog;
import java.util.Scanner;
public class maximum_of_index {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements : ");
int n = sc.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements : ");
for(int i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
System.out.println("Maximum value is : ");
for(int i=0;i<n;i++)
{
for(int j=n-1;j>=0;j++)
{
while(i<j)
{
if(a[i]>a[j])
{
System.out.println(j-i);
return;
}
else
{
System.out.println("Failed!!");
return;
}
}
}
}
}
}