-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMaxi.java
More file actions
30 lines (27 loc) · 759 Bytes
/
Maxi.java
File metadata and controls
30 lines (27 loc) · 759 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
package accentureQ;
import java.util.Scanner;
public class Maxi {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Length of array");
int n = sc.nextInt();
int []arr= new int[n];
System.out.println("Input array");
for (int i=0; i<n; i++){
arr[i] = sc.nextInt();
}
maxElem(arr,n);
}
static void maxElem(int []arr, int n){
int max = 0;
int index = 0;
for (int i = 0; i<n; i++){
if (arr[i]> max){
max = arr[i];
index = i;
}
}
System.out.println(max);
System.out.println(index);
}
}