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]);
}
}
}
Related Post: BlueJ Programs on Numeric Array
No comments:
Post a Comment