Skip to content

Commit bc8456a

Browse files
authoredFeb 6, 2023
Create 16.2 Min of Array Element.java
1 parent ec51819 commit bc8456a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
 

‎16.2 Min of Array Element.java

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*Suppose that you are asked to input the size of an array and then enter integer type elements in it. Write a program which works as follows: 1) If input of array size is less than 1, then "Invalid Array Size" should be displayed and no other input should be taken. 2) Find and print the smallest element in the array.
2+
3+
Input Format
4+
5+
Program should take 2 types of inputs in following sequence: 1) Size of array 2) Elements in array Example: 4 22 44 12 56
6+
7+
Constraints
8+
9+
Size of the array should be greater than 0. i.e. 0 < n <50
10+
11+
Output Format
12+
13+
If input of array size is negative, then "Invalid Array Size" should be displayed and no other input should be taken. If input array is: 22 44 12 56 then print smallest element as: 12
14+
15+
Sample Input 0
16+
17+
4
18+
22 44 12 56
19+
Sample Output 0
20+
21+
12
22+
*/
23+
import java.io.*;
24+
import java.util.*;
25+
26+
public class Solution {
27+
28+
public static void main(String[] args) {
29+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
30+
Scanner sc = new Scanner(System.in);
31+
int size = sc.nextInt();
32+
if(size>0 && size<50)
33+
{
34+
int []arr = new int[size];
35+
for(int i=0;i<size;i++)
36+
arr[i]=sc.nextInt();
37+
int min = arr[0];
38+
for(int i=1;i<size;i++)
39+
{
40+
if(arr[i]<min)
41+
min = arr[i];
42+
}
43+
System.out.print(min);
44+
}
45+
else
46+
{
47+
System.out.print("Invalid Array Size");
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)
Please sign in to comment.