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
{
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
{
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 sederhana”);
System.out.println(”2.Simetris sederhana”);
System.out.println(”3.Transitif sederhana”);
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
{
for (int j=0; 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
{
for (int j=0; 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
{
for (int j=0; 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;
}
}
}
Tidak ada komentar:
Posting Komentar