-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallEl.java
More file actions
36 lines (34 loc) · 874 Bytes
/
SmallEl.java
File metadata and controls
36 lines (34 loc) · 874 Bytes
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
import java.util.Scanner;
public class SmallEl {
public static void main(String arg[])
{
int arr[] = new int[100];
int n,small=0;
System.out.print("Enter the number of elements: ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(arr[i]<arr[j+1])
{
int temp;
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.print("The smallest Element is: "+ arr[n-1]);
}
}