Array : A homogeous set of finit elements which is stored in a continues memory location under certain name, is called array.

Example:
int a[]=new int[5];
a[0] =4;
a[1] =6;
a[2] =8;
a[3] =10;
a[4] =15;

or

int a[]={4,6,8,10,15};


length: This field is used to return the number of elements of a given array.

Write a program to sort given array in ascending order using selection sort technique.

class sort
{
 public static void main(String args[])
 {
  int a[]={55,33,11,22,44}
  int n=a.length;
  int i,j,temp;
  System.out.println("Before swapping array elemts");
  
  for(i=0;i<=n-1;i++)
   System.out.println(a[i]);
   
   for(i=0;i<=n-2;i++)
   {
    for(j=i+1;j<=n-1;j++)
    {
     if(a[i]>a[j])
     {
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
     }
    }
   }
  System.out.println("Sorted array elements are :");
  System.out.println(a[i]);
 }
}
Axact

Narendra

Hello, everyone! I am Narendra Bagul founder of Javanotes9. First of all thank you for visiting my blog. Hope you all like my java notes as well. I'm young part time blogger and a Computer Engineering student. I started blogging as a hobby. Now here I'm sharing my little acquired knowledge about my favorite programming language JAVA.

Post A Comment: