Terangi Jiwamu dengan Kata kata ilmiah


Posting-posting lagi hehe,,

ini tugas praktikum saya sebenarnya semoga bermanfaat buat yang lagi nyari-nyari,,,

ini listing programnya

import java.io.*;

class relasihimpunan

{

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

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

{

System.out.print(“masukkan banyaknya himpunan A:”);

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

int himpA [] = new int[x];

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

{

System.out.print(“masukkan 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.println();

System.out.println(“jenis relasi”);

System.out.println(“====================”);

System.out.println(“1.Reflektif “);

System.out.println(“2.Simetris “);

System.out.println(“3.Transitif “);

System.out.println(“====================”);

System.out.print(“masukkan jenis relasi yang diinginkan: “);

String b=input.readLine();

int pil=Integer.parseInt(b);

System.out.println();

switch (pil)

{

case 1:

//membuat relasi reflektif himpunan A

System.out.print(“Relasi R={“);

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

{

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

{

if (himpA[i]==himpA[j])

{

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

if (j!=x-1)

System.out.print(“,”);

}

}

}

System.out.println(“}”);

System.out.println();

break;

case 2 :

//membuat relasi simetris himpunan A

System.out.print(“Relasi R={“);

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

{

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

{

if (himpA[i] !=himpA[j])

{

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

if (j!=x-1)

System.out.print(“,”);

}

}

if (i!=x-1)

System.out.print(“,”);

}

System.out.println(“}”);

System.out.println();

break;

case 3 :

//membuat relasi transitif

System.out.print(“Relasi R={“);

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

{

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

{

if (himpA[i] !=himpA[j])

{

if (i%2!=0)

{

if (j%2==0)

{

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

if (j!=x-1)

System.out.print(“,”);

}

}

else

{

if (j%2!=0)

{

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

if (j!=x-1)

System.out.print(“,”);

}

}

}

}

}

System.out.println(“}”);

System.out.println();

break;

default:

System.out.println(“pilihan tak ada dalam daftar!!”);

break;

}

}

}

 

untuk source code nya dapat di download disini

dan untuk logika programnya silahkan download disini

About these ads

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

Tag Cloud

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: