Java program to sort entered element in the Array

Sort entered element in the Array

This program shows the concept to sort entered element in the Array.Sorting means arranging the element in either ascending or descending order.Here we have sort the element in ascending order i.e. increasing order.

import java.util.*;
class scan
{
 public static void main(String arg[])
  {
   int x[]=new int[100];
   int y,j,i,v;
   Scanner kb=new Scanner(System.in);
   System.out.println("Enter size of array");
   y=kb.nextInt();
   
   System.out.println("Enter Elements in Array:-");
   for(i=0;i<y;i++)
    {
	 x[i]=kb.nextInt();
	}
	
	for(i=0;i<y;i++)
	{
		for(j=i+1;j<y;j++)
		{
			if(x[i]>x[j])
			{
				v=x[i];        
				x[i]=x[j];
				x[j]=v;
			}
		}
	}
	System.out.println("Sorted Array is:- ");
	 for(i=0;i<y;i++)
	 {
		 System.out.println(x[i]);
	 }
  }
}

OUTPUT:-

sort entered element in the Array


Comment below if you are facing any problem


Also read

Java Program to find greatest Element in array
Java program to search an entered element in array
Java Program to enter Elements of your choice in Array


Summary
Java program to sort entered element in the Array
Article Name
Java program to sort entered element in the Array
Description
This program shows the concept to sort entered element in the Array.Sorting means arranging the element in either ascending or descending order.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *