-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccenture_19.java
More file actions
55 lines (44 loc) · 1.48 KB
/
Copy pathaccenture_19.java
File metadata and controls
55 lines (44 loc) · 1.48 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
45
46
47
48
49
50
51
52
53
54
55
/*
Problem Statement :
You are given a function, void MaxInArray(int arr[], int length); The function accepts an integer array ‘arr’ of size ‘length’ as its argument. Implement the function to find the maximum element of the array and print the maximum element and its index to the standard output
(STDOUT). The maximum element and its index should be printed in separate lines.
Note:
Array index starts with 0
Maximum element and its index should be separated by a line in the output
Assume there is only 1 maximum element in the array
Print exactly what is asked, do not print any additional greeting messages
Example:
Input:
23 45 82 27 66 12 78 13 71 86
Output:
86
9
Explanation:
86 is the maximum element of the array at index 9.
*/
import java.util.*;
public class accenture_19 {
void MaxInArray(int arr[], int length){
int max=Integer.MIN_VALUE;
for(int i=0;i<length;i++){
if(arr[i]>max)
max=arr[i];
}
System.out.println(max);
for(int i=0;i<length;i++){
if(arr[i]==max)
System.out.println(i);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
accenture_19 ob=new accenture_19();
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
ob.MaxInArray(a, n);
sc.close();
}
}