Skip to content

Commit 5f94eb8

Browse files
committed
print the smallest element in an array
1 parent 4911222 commit 5f94eb8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

smallest_element_array.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.Scanner;
2+
class smallestelement
3+
4+
{
5+
public static void main(String[] args)
6+
{
7+
int [] a = new int [10];
8+
Scanner s=new Scanner(System.in);
9+
System.out.print("ENTER THE NO OF ELEMNTS:");
10+
int n=s.nextInt();
11+
System.out.println("ENTER THE ARRAY ELEMENT:");
12+
for(int i=0;i<n;i++)
13+
a[i]=s.nextInt();
14+
15+
int min = a[0];
16+
for (int i = 0; i <n; i++)
17+
{
18+
19+
if(a[i] <min)
20+
min = a[i];
21+
}
22+
System.out.println("Smallest element present in given array: " + min);
23+
}
24+
}

0 commit comments

Comments
 (0)