File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ //Program to find the maximum and minimum value in an array of size m passed as argument.
2+ import java .util .Scanner ;
3+
4+ public class ArrayMinMax
5+ {
6+ public static void main (String args []) {
7+ int size = Integer .parseInt (args [0 ]);
8+ System .out .print ("\n Size of Array is: " + size );
9+ int [] arr = new int [size ]; // Declare an array variable
10+ Scanner reader = new Scanner (System .in );
11+ System .out .print ("\n Enter the elements of the array --------" );
12+ for (int i = 0 ; i < size ; i ++ )
13+ {
14+ System .out .print ("\n Enter the " + (i +1 ) + " element = " );
15+ arr [i ] = reader .nextInt ();
16+ }
17+ System .out .print ("\n Entered array is ----------\n " );
18+ for (int i = 0 ; i < size ;i ++)
19+ {
20+ System .out .print ("\t " +arr [i ]);
21+ }
22+ // Code for finding Maximum and Minimum by appliyning linear search
23+ int max = arr [0 ];
24+ int min = arr [0 ];
25+ for (int i = 1 ; i <size ; i ++)
26+ {
27+ if (max <arr [i ])
28+ {
29+ max = arr [i ];
30+ }
31+ if (min >arr [i ])
32+ {
33+ min = arr [i ];
34+ }
35+ }
36+ System .out .print ("\n Maximum of the array is: " + max );
37+ System .out .print ("\n Minimum of the array is: " + min );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments