Enter the values in array and arrange in increasing order

//Enter the values in array and arrange in increasing order.


import java.util.*;

class M
{
public static void main(String args[])
{
int a[]=new int[5];
int largest_number=0;
System.out.println("Enter the 5 values of an array:");
Scanner sc=new Scanner(System.in);
for(int i=0;i<=4;i++)
{
a[i]=sc.nextInt();

}
int temp=0;
for(int i=0;i<5;i++)
{
for(int j=i+1;j<=4;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;

}
}
}

System.out.println("After arranging in increasing order array is:\n");

for(int i=0;i<5;i++)
{
System.out.println(a[i]);
}
}
}


OUTPUT:
Enter the 5 values of an array:
3
2
1
4
5
After arranging in increasing order array is:
1
2
3
4
5

No comments:

Post a Comment