JAVA = “Fungsi satu-satu”


LISTING PROGRAM

import java.io.*;

public class aldy {

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 i = 0; i<y; i++)

{

System.out.print(“Elemen B ke- “+(i+1)+” :”);

String a=input.readLine();

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

}

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

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

{

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

if (i!=y-1)

System.out.print(“,”);

}

System.out.println(“}”);

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 k = 0; k<y; k++)

{

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

{

System.out.print(“(“+himpA[k]+”,”+himpB[l]+”)”);

System.out.print(“,”);

}

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

{

for (int n =(m-y); n<(m-y); n++)

{

System.out.print(“(“+himpA[m]+”,”+himpB[n]+”)”);

if (m!=x-1)

System.out.print(“,”);

}

}

}

}

}

}

System.out.println(“}”);

}

}

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