Monday, August 12, 2019

BlueJ Program on Merging Two Arrays





 Another program on BlueJ Array. Two arrays will be merged using BlueJ codings.

Given two one-dimensional array A and B which are sorted in accending order.  Write a programin BlueJ  to merge them into a single sorted array C that contains every elements of A and B

class Arr
{
int A[]={1,5,7,9,80},B[]={3,6,8,10,14},C[]=new int[10];
int i,j,x=0,t;
public void show()
{
  for(i=0;i< 5;i++)
  {
   C[x]=A[i];
   x++;
   }
   for(i=0;i< 5;i++)
   {
    C[x]=B[i];
    x++;
    }
   for(i=0;i< 10;i++)
   {
    for(j=i+1;j< 10;j++)
    {
     if(C[i] >C[j])
     {
      t=C[i];


      C[i]=C[j];
      C[j]=t;
     }
    }
   }
   System.out.println ("\nThe final array after merge is:\n");
   for(i=0;i< 10;i++)
   {
System.out.print (" " + C[i]);
  }
  }
}
  

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner