JAVA = “Fungsi Invers”


import java.io.*;

class invers {

private static BufferedReader input=new BufferedReader (new InputStreamReader(System.in));

public static void main(String[]args)throws Exception {

System.out.print(”Banyak Himpunan ‘A’ = “);

int x=Integer.parseInt(input.readLine());

int himpA[]=new int[x];

for (int i=0;i<x;i++)

{

System.out.print(”Elemen ‘A’ ke-”+(i+1)+” :”);

String a=input.readLine();

himpA[i]=Integer.parseInt(a);

}

System.out.print(”A={”);

for (int i=0;i<x;i++)

{

System.out.print(himpA[i]);

if (i!=x-1)

System.out.print(”,”);

}

System.out.println(”}”);

System.out.print(”Banyak Himpunan ‘B’ = “);

int y=Integer.parseInt(input.readLine());

int himpB[]=new int[y];

for (int j=0;j<y;j++)

{

System.out.print(”Elemen ‘B’ ke-”+(j+1)+” :”);

String b=input.readLine();

himpB[j]=Integer.parseInt(b);

}

System.out.print(”B={”);

for (int j=0;j<y;j++)

{

System.out.print(himpB[j]);

if (j!=y-1)

System.out.print(”,”);

}

System.out.println(”}”);

// Fungsi

System.out.print(”F(A->B)={”);

if (x<=y)

for (int i=0;i<x;i++)

{

for (int j=i;j<=i;j++)

System.out.print(”(”+himpA[i]+”,”+himpB[j]+”)”);

if (i!=x-1)

System.out.print(”,”);

}

else

{

for (int i=0;i<y;i++)

{

for (int j=i;j<=i;j++)

System.out.print(”(”+himpA[i]+”,”+himpB[j]+”)”);

System.out.print(”,”);

}

for (int i=y;i<x;i++)

{

for (int j=(i-y);j<=(i-y);j++)

System.out.print(”(”+himpA[i]+”,”+himpB[j]+”)”);

if (i!=x-1)

System.out.print(”,”);

}

}

System.out.print(”invers={”);

if (x<=y)

for (int i=0;i<x;i++)

{

for (int j=i;j<=i;j++)

System.out.print(”(”+himpB[j] +”,”+ himpA[i]+”)”);

if (i!=x-1)

System.out.print(”,”);

}

else

{

for (int i=0;i<y;i++)

{

for (int j=i;j<=i;j++)

System.out.print(”(”+himpB[j] +”,”+ himpA[i]+”)”);

System.out.print(”,”);

}

for (int i=y;i<x;i++)

{

for (int j=(i-y);j<=(i-y);j++)

System.out.print(”(”+himpB[j] +”,”+ himpA[i]+”)”);                                            if (i!=x-1)

System.out.print(”,”);

}

}

}

}

This entry was posted in JAVA. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s