Senin, 27 September 2010

fungsi invers (java)

import java.io.*;

class fungsi

{

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

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

{

//himpunan A

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

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

int himpA[]=new int[x];

for (int i=0;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

{

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

if (i!=x-1)

System.out.print(”,”);

}

System.out.println(”}”);

//himpunan B

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

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

int himpB[]=new int[y];

for (int j=0;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

{

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

{

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

{

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

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

System.out.print(”,”);

}

for (int i=y;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

{

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

{

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

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

System.out.print(”,”);

}

for (int i=y;i

{

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

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

System.out.print(”,”);

}

}

}

}

Tidak ada komentar:

Posting Komentar