-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMinMax.java
More file actions
49 lines (38 loc) · 1.14 KB
/
ArrayMinMax.java
File metadata and controls
49 lines (38 loc) · 1.14 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
//8:Write a Java program to find the maximum and minimum value of an array.
import java.util.Arrays;
import java.util.Scanner;
public class ArrayMinMax {
public static int getMaxValue(int[] arr) {
int maxvalue = arr[0];
for(int index = 0;index<arr.length;index++) {
if(arr[index]>maxvalue)
maxvalue=arr[index];
}
return maxvalue;
}
public static int getMinValue(int[] arr) {
int minvalue=arr[ 0 ];
for(int index=0;index<arr.length;index++) {
if(arr[ index ] < minvalue)
minvalue = arr[ index ];
}
return minvalue;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size;
System.out.print("Enter array size :");
size=input.nextInt();
int arr[ ] = new int [ size ];
for(int index=0;index<arr.length;index++) {
System.out.print("Enter Array elements :");
arr[ index ] = input.nextInt();
}
System.out.println("Array elements are : "+Arrays.toString(arr));
int maxvalue = getMaxValue(arr);
System.out.println("Maximum Value : "+maxvalue);
int minvalue = getMinValue(arr);
System.out.println("Minimum Value : "+minvalue);
input.close();
}
}