public class gabunglarik
{
public static void main(String[] args)
{
int [] a1={6,7,8,9,10};
int [] a2={1,2,3,4,5};
int n1=a1.length;
int n2=a2.length;
int a3[]=new int[(n1+n2)];
ar(a1, a2, n1, n2);
as(a1, a2, a3, n1, n2);
}
public static void ar(int ar1[], int ar2[], int an1, int an2)
{
System.out.println("\nIsi a1[] \n--------------------");
for (int i=0;i<an1;i++)
{
System.out.println("Nilai a1["+i+"] ==> "+ar1[i]);
}
System.out.println("\n\nIsi a2[] \n--------------------");
for (int i=0;i<an2;i++)
{
System.out.println("Nilai a2["+i+"] ==> "+ar2[i]);
}
}
public static void as(int as1[], int as2[], int as3[], int asn1, int asn2)
{
if (as1[(asn1-1)]<as2[0])
{
System.out.println("\n\nIsi a3[] (Gabungan a1[] dan as2[]) \n--------------------");
for (int i=0;i<asn1;i++)
{
System.out.print("Nilai a3["+i+"] ==> ");
as3[i]=as1[i];
System.out.println(as3[i]);
}
int h=0;
for (int x=asn1;x<(asn1+asn2);x++)
{
System.out.print("Nilai a3["+x+"] ==> ");
as3[x]=as2[h];
System.out.println(as3[x]);
h=h+1;
}
}
else if(as1[(asn1-1)]>as2[0])
{
System.out.println("\n\nIsi a3[] (Gabungan a1[] dan a2[]) \n--------------------");
for (int i=0;i<asn1;i++)
{
System.out.print("Nilai a3["+i+"] ==> ");
as3[i]=as2[i];
System.out.println(as3[i]);
}
int h=0;
for (int x=asn1;x<(asn1+asn2);x++)
{
System.out.print("Nilai a3["+x+"] ==> ");
as3[x]=as1[h];
System.out.println(as3[x]);
h=h+1;
}
}
}
}
Rabu, 11 Juni 2014
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar