-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray.java
57 lines (38 loc) · 1.42 KB
/
Array.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Read inputSTDIN. Print your output to STDOUT*/
import java.util.*;
import java.io.*;
public class Array{
public static void mMax(int arr[]){
// array is sorted when enter this method
int i;
// logic for finding highest but it also find by arr[arr.length-1]
// Array Size start from 1 so it require arr[arr.length-1] for highest
int max=arr[0];
for(i=1;i<arr.length;i++){
if(arr[i]>max)
max =arr[i];
}
max =max;
System.out.println("MAX of Array :" +max);
// for second last index of array
System.out.println("Second largest : " +arr[arr.length-2]);
System.out.println("largest : " +arr[arr.length-1]);
}
public static void main(String args[] ) throws Exception {
//Write code here
int i;
Scanner scan=new Scanner(System.in);
System.out.print("Array Size :");
int mArraySize =scan.nextInt();
int[] arr= new int[mArraySize];// array declared & instantiated
System.out.print("Enter no in array : ");
for(i=0;i<arr.length;i++){
arr[i] =scan.nextInt();
}
Arrays.sort(arr);
for(i=0;i<arr.length;i++){
System.out.println("i : "+ i+ " Value : " +arr[i]);
}
mMax(arr);
}
}