Arranging given array to Ascending Order.

import java.util.*;
class DescendingOrdeInArray
{
public static void main(String[] args)
{
int i,j,temp;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");
int n= sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter the elements of array");
for(i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("Array in ascending order is");
for(i=0;i<n;i++)
{
System.out.print(arr[i] + " ");

}
}
}
        
                            Output : -
        


Comments

Popular posts from this blog

LCM and GCD/HCF code

Binary Search using Java

Calculator Using Switch Case in Java